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 10-06-2008, 11:30 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 177
Default I've got a line of code that works fine in sim but not on iPhone

Code:
// Default settings
NSString *var1 = [NSString stringWithString:@"YES"];
NSString *var2 = [NSString stringWithString:@"40.0"];
NSString *var3 = [NSString stringWithString:@"YES"];
NSString *var4 = [NSString stringWithString:@"40.0"];
NSString *var5 = [NSString stringWithString:@"NO"];
NSString *var6 = [NSString stringWithString:@"5.0"];
	
// Register initial default settings
NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:var1, @"Var1", var2, @"Var2", var3, @"Var3", var4, @"Var4", var5, @"Var5", var6, @"Var6"];
Ignore the naming, it's just to protect my code. Basically I'm using YES and NO for BOOL vars, because when you fetch it as a BOOL, it can use a string and use YES or NO to determine the value of the BOOL. The other ones are floats, same thing...it can pull a float from a string.

This works fine in the sim, I can register this array and write to it...everything works as expected. In my iPhone, it crashes...and it has nothing to do with the UserDefaults stuff...it's that dictionary...if I try to create it on the iPhone...it crashes.
skinrock is offline   Reply With Quote
Old 10-06-2008, 11:36 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 177
Default

Okay, turns out that exact code doesn't work in the sim, but what does work is if I create the strings like so:

Code:
NSString *var1 = @"YES";
That works fine, and still doesn't work in the iPhone.
skinrock is offline   Reply With Quote
Old 10-06-2008, 11:53 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 177
Default

Interesting, I added nil to the very end of my key/object pair list, and that fixed it. I have an app that is currently for sale that didn't need the "nil" part...I only had two key/object pairs, but it would be odd that the number of pairs has an effect.
skinrock is offline   Reply With Quote
Old 10-07-2008, 12:00 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 288
Default

Arrays need the "nil" at the end to function properly.

glad you found the issue.
Kenrik is offline   Reply With Quote
Old 10-07-2008, 12:04 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 177
Default

Ya, I remember seeing it, which is the only reason I thought of it...but I was hesitant because like I said, I have another app where it didn't affect it. Oh well, time for bed.
skinrock is offline   Reply With Quote
Old 10-07-2008, 12:07 AM   #6 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

The nil at the end of the list is required by the api as indicated by the method prototype:

Code:
- (id)initWithObjectsAndKeys:(id)firstObject, ... NS_REQUIRES_NIL_TERMINATION;
If you left it out and it didn't crash that was just luck.
PhoneyDeveloper is offline   Reply With Quote
Reply

Bookmarks

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: 233
15 members and 218 guests
ADY, AragornSG, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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