Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-16-2010, 03:37 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 4
Default Global NSMutableArray

Pretty simple, what's the best way of creating and accessing a 'global' NSMutableArray?!

Its driving me mad!

thanks, Nick
Gatzy118 is offline   Reply With Quote
Old 02-16-2010, 05:34 PM   #2 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Declaring it in the .h file.

Hi again btw.
ZunePod is offline   Reply With Quote
Old 02-17-2010, 09:39 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 4
Default

Quote:
Originally Posted by ZunePod View Post
Declaring it in the .h file.

Hi again btw.
Im not sure you understand. I need to declare an NSMutableArray and then be able to access (run instance methods) a single instance of it from anywhere in the application.

How?!
Gatzy118 is offline   Reply With Quote
Old 02-17-2010, 09:46 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: New York
Age: 23
Posts: 144
Default

Just like he said, declare the NSMutableArray in your header file
__________________
Check out my website and forum!
The best way to learn is to do.
My Apps:
iPill Trackr
Reminder
Reminder Lite
iSupplement
Million Shake Challenge
Proxim
Rainbow
csheldrick is offline   Reply With Quote
Old 02-17-2010, 04:14 PM   #5 (permalink)
iPhone SDK learner
 
Join Date: Feb 2010
Location: Illinois, USA
Posts: 417
Default

Quote:
Originally Posted by csheldrick View Post
Just like he said, declare the NSMutableArray in your header file
if you mean in multiple view controllers, make a singleton and declare it there
Batman is offline   Reply With Quote
Old 02-24-2010, 12:33 AM   #6 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 57
Default

Quote:
Originally Posted by Batman View Post
if you mean in multiple view controllers, make a singleton and declare it there
I would use subclasses

Code:
//say your .h and .m file is named "View"

//in the .h file declare all your variables and methods

//this code goes under . h file
 
@interface View: ViewController{

NSMutableArray *Array

}

@end


@interface View (subclass1...)

//methods are only allowed under the subclasses no variables

@end


@interface View (subclass2...)

//methods are only allowed under the subclasses no variables

@end


Code:
//this code goes under a new .m file
//not the .m file of "View"

@implementation View (subclass1)

//each subclass gets it own .m file
//and you can use every and any variable in any subclass globally from the "View" .h file

@end


@implementation View (subclass2)

//each subclass gets it own .m file
//and you can use every and any variable in any subclass globally from the "View" .h file

@end


I Hope This Helps & Happy Coding,
GetOffTheCourt
GetOffTheCourt is offline   Reply With Quote
Old 02-24-2010, 11:08 AM   #7 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,526
Default

The way to declare a global is to declare it outside of any @interface...@end block, and to define in outside of any @implementation...@end block, as in:

Code:
//this code goes under some .h file (it doesn't matter which one)
extern NSMutableArray *globalArray;

@interface (of some class - it doesn't matter which one)
...
@end
Then define globalArray as in:
Code:
NSMutableArray *globalArray;
@implementation (any, it doesn't matter which one)
...
@end
And then, somewhere where you are sure it will only be executed once:
Code:
globalArray = (some alloc-type of NSMutable Array creation method, retaining)
Now you have a singleton NSMutableArray you can access from anywhere. Just don't ever release it. It's memory will be reclaimed automatically when your app closes.

Robert Scott
Ypsilanti, Michigan
RLScott is offline   Reply With Quote
Old 07-30-2010, 03:13 PM   #8 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

I have been reading your reply to this post and would like to use it in my App.

What I am trying to do is read the content of a record held in an SQLite table and use the result in a number of views. The SQLite result is currently written into an array. At the moment I display the result in a UIScrollView and it works fine but the amount of scrolling is becoming far to long.

I thought I would split the result between separate views. Reading your reply within the post I thought I would try and use a global array.

The code which creates my current array is:
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic -- create and push a new view controller

	
	NSString *name = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

		
	if(self.countryView == nil) {
		CountryDetailViewController *viewController = [[CountryDetailViewController alloc] initWithNibName:@"CountryDetailViewController" bundle:nil];
		self.countryView = viewController;
		[viewController release];
		 [tableView deselectRowAtIndexPath:indexPath animated:YES];
	}
	
	countries = [[NSMutableArray alloc]init];
	
	sqlite3 *db = [iTravelv113AppDelegate getNewDBConnection];
	
	NSMutableString *query;

	query = [NSMutableString stringWithFormat:@"select * from countryList where countryName = '%@'", name];
	const char *sql =  [query UTF8String];
	sqlite3_stmt *compiledStatement = nil;
	
	if(sqlite3_prepare_v2(db, sql, -1, &compiledStatement, NULL) == SQLITE_OK) {
		// Loop through the results and add them to the feeds array
		while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
			// Read the data from the result row
			NSString *aName = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] autorelease];
			NSString *aCountry = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] autorelease];
			NSString *aCapital = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)] autorelease];
			NSString *aLanguageF = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)] autorelease];
			NSString *aLanguageS = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)] autorelease];
			NSString *aVoltage = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)] autorelease];
			NSString *aFreq = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)] autorelease];
			NSString *aDialCode = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)] autorelease];
			NSString *aCurrencyCode = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] autorelease];
			NSString *aCurrencyName = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 9)] autorelease];
			NSString *aCurrencySymbol = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] autorelease];
			NSString *aPhonePolice = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 11)] autorelease];
			NSString *aPhoneMedical = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 12)] autorelease];
			NSString *aPhoneFire = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 13)] autorelease];
			NSString *aCountryFlag = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 15)] autorelease];
			NSString *aCountryKey = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 14)] autorelease];
			NSString *aCountryOutlet = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 16)] autorelease];
			NSString *atimeZone1 = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 17)] autorelease];
			NSString *atimeZone2 = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 18)] autorelease];
			NSString *atimeZone3 = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 19)] autorelease];
			
			
			// Create a new country object with the data from the database
			Country *country = [[Country alloc] initWithName:aName countryName:aCountry capitalCity:aCapital
					firstLang:aLanguageF secondLang:aLanguageS voltage:aVoltage freq:aFreq dialCode:aDialCode 
					currencyCode:aCurrencyCode currencyName:aCurrencyName currencySymbol:aCurrencySymbol
					phonePolice:aPhonePolice phoneMedical:aPhoneMedical phoneFire:aPhoneFire countryFlag:aCountryFlag
												  countryKey:aCountryKey countryOutletType:aCountryOutlet
													  timeZone1:atimeZone1 timeZone2:atimeZone2 timeZone3:atimeZone3];
			
			// Add the country object to the countries Array
			[countries addObject:country];
			
			[country autorelease];

	
	// Setup the animation
	[self.navigationController pushViewController:self.countryView animated:YES];
	// Set the title of the view to the countries name
	self.countryView.title = [country countryName];
	
	[self.countryView.countryName setText:[country countryName]];
	[self.countryView.capitalCity setText:[country capitalCity]];
	[self.countryView.firstLang setText:[country firstLang]];
	[self.countryView.secondLang setText:[country secondLang]];
	[self.countryView.currencyCode setText:[country currencyCode]];
	[self.countryView.currencyName setText:[country currencyName]];
	[self.countryView.voltage setText:[country voltage]];
	[self.countryView.freq setText:[country freq]];
	[self.countryView.phonePolice setText:[country phonePolice]];
	[self.countryView.phoneMedical setText:[country phoneMedical]];
	[self.countryView.phoneFire setText:[country phoneFire]];
	[self.countryView.dialCode setText:[country dialCode]];
	[self.countryView.countryOutletType setText:[country countryOutletType]];
	[self.countryView.timeZone1 setText:[country timeZone1]];
	[self.countryView.timeZone2 setText:[country timeZone2]];
	[self.countryView.timeZone3 setText:[country timeZone3]];
			
	[self.countryView setCountry:[country countryName]];
			
	
			
	UIImage *currencySymbol = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[country currencySymbol] ofType:@"png"]];
	self.countryView.currencySymbol.image = currencySymbol;	
			[currencySymbol autorelease];
			
	UIImage *countryFlag = [[UIImage alloc]  initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[country countryFlag] ofType:@"gif"]];			
	self.countryView.countryFlag.image = countryFlag;
			[countryFlag autorelease];
	
	}
		
	}
	// Release the compiled statement from memory
	sqlite3_finalize(compiledStatement);
	

	
}
In the .h I have made a change from "NSMutableArray *countries" which was inside of the @interface...@end block to "extern NSMutableArray *countries;" which is now outside of the @interface...@end bloc. I have also declared "extern NSMutableArray *countries;" before the @implementation section in the .m file.

The part I am not clear about is:
Code:
globalArray = (some alloc-type of NSMutable Array creation method, retaining)
Can you advise me how to implement my array in to this statement so I can use it in other views.

Many thanks for any advice and help you can provide.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 07-30-2010, 04:11 PM   #9 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,526
Default

By changing the .h file
Quote:
from "NSMutableArray *countries" which was inside of the @interface...@end block to "extern NSMutableArray *countries;" which is now outside of the @interface...@end block
you are saying that countries, which used to be an instance variable of the class, is now a global variable. So countries is what you want to use instead of globalArray.

Next, you should not use "extern" in the .m file. "extern" is only for the declaration in the .h file, not for the actual variable definition in the .m file.

Finally, you already created countries and it is retained (because you used alloc and did not release it).

So if you take away that one unnecessary extern, then you would have the setup you need to make countries a global NSMutableArray. To access it in other views, only need to import the .h file that declares countries into the .m file of those views.

I should warn you that using a global variable like this invites problems if you are careless. Remember that countries is not actually the NSMutableArray itself. It is just a pointer to that NSMutableArray. Like all Objective-C objects, this object can only be accessed through pointers. And the memory that it points to needs to be dynamically managed. Normally this dynamic memory management is taken care of for you when you make a property of an object.

By looking at your code, I see that you set countries in response to a didSelectRowAtIndexPath. Therefore you might set countries more than once. When you do that, the old NSMutableArray that countries used to point to becomes leaked memory, unless you first release it. This would have been handled automatically for you if you were content to use properties and the standard retaining setter that comes with it. But by implementing a global variable, you have abandoned the use of properties. So you have to do the work that the properties would have done for you automatically. If you really understand the retain/release system and are committed to taking the care needed to release dynamically allocated memory at just the right time, then you can make this work. But this is not normally done.

OK, I have done my best to warn you against using a global variable as a pointer to a NSMutableArray. So the choice is up to you.
RLScott is offline   Reply With Quote
Old 07-30-2010, 04:20 PM   #10 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

Many thanks for such a details response. After reading tier reply I think I need to look at how I am going the get the result I need in another way.

Because "countries" will be set more than once your right in saying it's not the way to do it. The only reason I was looking at using a global array is because I cannot think of any other way to retain the variables in each of the views.

I need to rethink the whole process.

Again, many thanks for your advice.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 07-30-2010, 04:33 PM   #11 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,526
Default

How about making it a property of the app delegate? It would not be exactly global, but it would be accessible from anywhere.
RLScott is offline   Reply With Quote
Old 07-31-2010, 05:11 AM   #12 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

From what I have read, "and since I started trying to learn Objective C, which was back in March, I've done a lot of reading but not enough by the look of it" your suggestion is a great idea. The only problem I have is I am not sure how to implement it.

Do you have the time to show me the syntax I should use to make the "countries" array a property of the App delegate and how I would make a call to it from a UIView.

I think if I can get over this issue I may be home and dry.

Again, many thanks in advance.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 07-31-2010, 06:33 AM   #13 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,526
Default

See the end of my tutorial on globals here. Just use NSMutableArray countries instead of NSString userName. And never set the value of countries except with the setter:

appDelegate.countries =...
RLScott is offline   Reply With Quote
Old 07-31-2010, 10:51 AM   #14 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

Sorry to be a complete pain in the neck with this.

My appDelegate .h file is:
Code:
#import <sqlite3.h> // Import the SQLite database framework
#import <UIKit/UIKit.h>

@interface iTravelv113AppDelegate : NSObject <UIApplicationDelegate> {
    
    UIWindow *window;
    UINavigationController *navigationController;
	
	// Database variables
	NSString *databaseName;
	NSString *databasePath;
	
	NSMutableArray *countries;
	
	NSString *airportname;
	
	
	
	NSMutableArray *arrayOfCharacters;
	NSMutableDictionary *objectsForCharacters;
	
	NSMutableArray *arrayOfAirports;
	
	// Array to store the country objects
	NSMutableArray *airports;	
}

@property (nonatomic, retain) NSMutableArray *countries;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;


-(void)checkAndCreateDatabase;
+(sqlite3*)getNewDBConnection;
The appDelegate .m file is:
Code:
#import <sys/socket.h>
#import <netinet/in.h>
#import <arpa/inet.h>
#import <netdb.h>
#include <SystemConfiguration/SCNetworkReachability.h>

#import "iTravelv113AppDelegate.h"
#import "RootViewController.h"



@implementation iTravelv113AppDelegate

@synthesize window;
@synthesize navigationController;
@synthesize countries;
and so on...

I have a file which reads my SQL data and creates an ARRAY containing the record requested by the user. A part of the file is below:
Code:
// Create a new country object with the data from the database
Country *country = [[Country alloc] initWithName:aName countryName:aCountry capitalCity:aCapital
firstLang:aLanguageF secondLang:aLanguageS voltage:aVoltage freq:aFreq dialCode:aDialCode 
currencyCode:aCurrencyCode currencyName:aCurrencyName currencySymbol:aCurrencySymbol
phonePolice:aPhonePolice phoneMedical:aPhoneMedical phoneFire:aPhoneFire countryFlag:aCountryFlag
countryKey:aCountryKey countryOutletType:aCountryOutlet
timeZone1:atimeZone1 timeZone2:atimeZone2 timeZone3:atimeZone3];
			
// Add the country object to the countries Array
	[countries addObject:country];
	appDelegate.countries = countries;
	[country autorelease];
The part I am struggling with is assigning the content of the ARRAY to the "appDelegate.countries = countries". I know this is because I don't know how this is done even thou I have read and re-read your tutorial. Basically I am having a very thick head time.

Can you help me advance this issue a little further.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 07-31-2010, 03:56 PM   #15 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

again, sorry to be a pain in the neck.

I have gotten a little further, I now have the following in the file which reads the country record in to the array. I have changed he name of the array from countries to countriesList to avoid a clash with another var.
Code:
// Create a new country object with the data from the database
Country *country = [[Country alloc] initWithName:aName countryName:aCountry capitalCity:aCapital
firstLang:aLanguageF secondLang:aLanguageS voltage:aVoltage freq:aFreq dialCode:aDialCode 
currencyCode:aCurrencyCode currencyName:aCurrencyName currencySymbol:aCurrencySymbol
phonePolice:aPhonePolice phoneMedical:aPhoneMedical phoneFire:aPhoneFire countryFlag:aCountryFlag
countryKey:aCountryKey countryOutletType:aCountryOutlet
timeZone1:atimeZone1 timeZone2:atimeZone2 timeZone3:atimeZone3];
			
// Add the country object to the countries Array
[countries addObject:country];
			
iTravelv113AppDelegate  *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.countriesList = countries;
NSLog(@"The contents of countriesList = %@",appDelegate.countriesList);
[country autorelease];
The App complies without error but the output of the NSLog is:

2010-07-31 20:47:52.163 iTravelv113[2983:207] Database Successfully Opened
2010-07-31 20:47:52.165 iTravelv113[2983:207] The contents of countriesList = (
"<Country: 0x764a710>"
)

I am not to sure what this is telling me. Can you throw any light on the output.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 08-01-2010, 06:35 PM   #16 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

Please forget the last post or two. I am moving forward and I think I may have solved my issue.

I will let you know, many thanks again for your help.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 08-02-2010, 06:37 AM   #17 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

Having followed your tutorial I now have the following code.

I have created an NUMultableArray:
Code:
NSMutableArray *acountryList;
			
			acountryList = [NSMutableArray new];
			[acountryList addObject: aCountry];
			[acountryList addObject: aCapital];
			[acountryList addObject: aLanguageF];
			[acountryList addObject: aLanguageS];
			[acountryList addObject: aVoltage];
			[acountryList addObject: aFreq];
			[acountryList addObject: aDialCode];
			[acountryList addObject: aCurrencyCode];
			[acountryList addObject: aCurrencyName];
			[acountryList addObject: aCurrencySymbol];
			[acountryList addObject: aPhonePolice];
			[acountryList addObject: aPhoneMedical];
			[acountryList addObject: aPhoneFire];
			[acountryList addObject: aCountryFlag];
			[acountryList addObject: aCountryOutlet];
			[acountryList addObject: atimeZone1];
			[acountryList addObject: atimeZone2];
			[acountryList addObject: atimeZone3];
			
			

			
			iTravelv113AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
			//someClass.someString = appDelegate.userName;  //..to fetch
			appDelegate.countries = acountryList;     //..to write
which when test for content holds the correct data.

In my AppDeligate I have the following:
.h file:
Code:
@interface iTravelv113AppDelegate : NSObject <UIApplicationDelegate> {
    
    UIWindow *window;
    UINavigationController *navigationController;
	
	// Database variables
	NSString *databaseName;
	NSString *databasePath;
	
	NSMutableArray *countries;
	
	NSString *airportname;
	
	NSMutableArray *arrayOfCharacters;
	NSMutableDictionary *objectsForCharacters;
	
	NSMutableArray *arrayOfAirports;
	
	// Array to store the country objects
	NSMutableArray *airports;	
}

@property (nonatomic, retain) NSMutableArray *countries;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;


-(void)checkAndCreateDatabase;

+(sqlite3*)getNewDBConnection;
in the .m file:
Code:
@implementation iTravelv113AppDelegate

@synthesize navigationController;
@synthesize countries;
In the UIViewController where I want to use the content of the array I have:
.h file:
Code:
@interface LocalCurrencyViewController : UIViewController {
	
	NSMutableArray *countries;
	
	IBOutlet	UIScrollView		*scrollView;
	
	IBOutlet UITextView		*acountryName;
	IBOutlet UITextView		*acapitalCity;
	IBOutlet UITextView		*afirstLang;
	IBOutlet UITextView		*asecondLang;
	IBOutlet UITextView		*acurrencyName;
	IBOutlet UITextView		*acurrencyCode;
	IBOutlet UIImageView	*acurrencySymbol;
	IBOutlet UITextView		*avoltage;
	IBOutlet UITextView		*afreq;
	IBOutlet UITextView		*aphonePolice;
	IBOutlet UITextView		*aphoneMedical;
	IBOutlet UITextView		*aphoneFire;
	IBOutlet UITextView		*adialCode;
	IBOutlet UIImageView	*acountryFlag;
	IBOutlet UITextView		*acountryOutletType;
	IBOutlet UITextView		*atimeZone1;
	IBOutlet UITextView		*atimeZone2;
	IBOutlet UITextView		*atimeZone3;
	IBOutlet NSString		*aCountry;
	
	
}

@property (nonatomic, retain) NSMutableArray *countries;

@property (nonatomic, retain) IBOutlet UITextView *acountryName;
@property (nonatomic, retain) IBOutlet UITextView *acapitalCity;
@property (nonatomic, retain) IBOutlet UITextView *afirstLang;
@property (nonatomic, retain) IBOutlet UITextView *asecondLang;
@property (nonatomic, retain) IBOutlet UITextView *acurrencyName;
@property (nonatomic, retain) IBOutlet UITextView *acurrencyCode;
@property (nonatomic, retain) IBOutlet UIImageView *acurrencySymbol;
@property (nonatomic, retain) IBOutlet UITextView *avoltage;
@property (nonatomic, retain) IBOutlet UITextView *afreq;
@property (nonatomic, retain) IBOutlet UITextView *aphonePolice;
@property (nonatomic, retain) IBOutlet UITextView *aphoneMedical;
@property (nonatomic, retain) IBOutlet UITextView *aphoneFire;
@property (nonatomic, retain) IBOutlet UITextView *adialCode;
@property (nonatomic, retain) IBOutlet UIImageView *acountryFlag;
@property (nonatomic, retain) IBOutlet UITextView *acountryOutletType;
@property (nonatomic, retain) IBOutlet UITextView *atimeZone1;
@property (nonatomic, retain) IBOutlet UITextView *atimeZone2;
@property (nonatomic, retain) IBOutlet UITextView *atimeZone3;
@property (nonatomic, retain) IBOutlet NSString *aCountry;
.m file
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	
	iTravelv113AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
	UITextView.acountryName = appDelegate.countries;  //..to fetch
	NSLog(@"The contents of countries = %@",[countries  description]);	
}
but I am getting the following error:
"Accessing unknown setAcountryName class method, Object cannot be set, either readonly property or setter cannot be found".

Can you see anything I have missed.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 08-02-2010, 07:05 AM   #18 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,526
Default

Code:
	UITextView.acountryName = appDelegate.countries;
acountryName is not a property of UITextView. Why is UITextView there?
RLScott is offline   Reply With Quote
Old 08-02-2010, 07:27 AM   #19 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

Quote:
acountryName is not a property of UITextView. Why is UITextView there?
That's a good question and to be truthful I don't know. What I was trying to do is make the "acountryName" available so I could eventually use it in a view.

Assuming all the other code is correct, How do I call the content of the "countries" array so it can be used the the view I am working on.

I know I'm a pain in the neck, sorry. But I am learning fast, I think.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Old 08-02-2010, 10:14 AM   #20 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Warwickshire, United Kingdom
Posts: 163
Default

Hi Robert,

SUCCESS, I have change my code to:
Code:
iTravelv113AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
	NSArray *tempCountry  = appDelegate.countries;  //..to fetch
	ccountryName.text = [tempCountry objectAtIndex:0];
	ccurrencyName.text = [tempCountry objectAtIndex:8];
	ccurrencyCode.text = [tempCountry objectAtIndex:9];
Now I have the correct data displaying.

Robert, many thank for all your help.
__________________
Many thanks, keep safe and well.



Dereck
dcjones is offline   Reply With Quote
Reply

Bookmarks

Tags
global, nsmutablearray, variable

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 258
20 members and 238 guests
ADY, Alsahir, beleg_1998, Dani77, e2applets, iph_s, JasonR, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, Rudy, sebasx, sly24, timle8n1, Touchmint, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,758
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0