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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-12-2009, 06:59 PM   #1 (permalink)
freshking
Registered Member
 
Join Date: Oct 2008
Location: Munich, Germany
Posts: 108
freshking is on a distinguished road
Default Difficulties writing NSMutableArra to plist!

Hi all,

im having difficulties saving an nsmutablearray to a plist.
Before adding an object ty my array (services), I set a type for each object as shown below in order to differenciate how they are displayed in my tableView:

Quote:
typedef enum _StringType
{
Input, Received
} StringType;


@interface MyObject: NSObject
{
NSString* theString;
StringType type;

}
@property (nonatomic, retain) NSString* theString;
@property (readonly) StringType type;

-(id) initWithStringNSString*) aString andType: (StringType)_type;

@end

@implementation MyObject

@synthesize theString, type;

-(id) initWithString: (NSString*) aString andType: (StringType)_type{
self = [super init];
if( self != nil )
{
self.theString = aString;
type = _type;

}
return self;

}
//also add this in MyObject
-(void)dealloc
{
[theString release];
[super dealloc];
}

@synthesize theString, type;

@end
Quote:
- (void)sendAction: (id) sender {

//when something new is input by the user
MyObject* obj = [[MyObject alloc] initWithString:input.text andType: Input];
[services addObject: obj];
[obj release];

[tableView reloadData];
}
This is the my code for writing the array to the plist:

Quote:
- (void)applicationWillTerminateUIApplication *)application {

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *appDir = [[NSBundle mainBundle] resourcePath];
NSString *dest = [docsDir stringByAppendingPathComponent: @"old.plist"];
[services writeToFile:dest atomically: YES];
NSLog(@"Services array: %@", services);

}
And this is how my array looks in the log:

Quote:
2009-09-13 01:48:56.975 Texter[15619:20b] Services array: (
<MyObject: 0xd06510>,
<MyObject: 0xd31a10>,
<MyObject: 0xd8ba50>,
<MyObject: 0xd348f0>
)
For some reason, writeToFile: is unable the handle its operation with this array. With any other "normal" array the writing to the plist works perfectly. For example with:

Quote:
NSArray *example = [[NSArray alloc] initWithObjects:@"one", @"two", @"three", nil];
I guess I would have to convert the array to some other format but I need it like this so that the tableView knows how the arrange its cell content when loading from the plist according to each objects type.

I hope somebody can help me out here!
Thanks alot!
freshking is offline   Reply With Quote
 

» Advertisements
» Online Users: 633
18 members and 615 guests
007007, ADY, appsman, baja_yu, Bertrand21, clarky07, dacapo, flamingliquid, GHuebner, greeneye82, jaystudio, marleneZ, talyn4, tapan.raju, thorb65, trisvandis, TylerBetable, ukneeq
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,182
Threads: 93,921
Posts: 402,158
Top Poster: BrianSlick (7,968)
Welcome to our newest member, appsman
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:47 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.