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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-04-2010, 04:39 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
Vladdmeir is on a distinguished road
Exclamation NSUser Defaults problem

Hi,

I'm having a problem with NSUser Defaults,
I'm doing a one-time set up of my app and I use this code to register what the NSUser Defaults thing should do:

Code:
setups = [[NSString alloc] initWithFormat:@"YES"];
		
		setup.hidden = setups;
		
		NSUserDefaults *stringDefault2 = [NSUserDefaults standardUserDefaults];
		[stringDefault2 setObject:setups forKey:@"stringKey4"];
This works OK as button vanishes dutifully, but note that there is this warning on the second line:
Passing argument 1 of "setHidden:" makes integer from pointer without a cast.

But the button still vanishes, so it works?

I then call the string back using this method which receives the same warning as above

Code:
 setup.hidden = [[NSUserDefaults standardUserDefaults] objectForKey:@"stringKey4"];
But the button does not get hidden, and I know it must be something to do with the warnings? Any help would be loved
Vladdmeir is offline   Reply With Quote
Old 01-04-2010, 04:57 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Try using
Code:
[... setBool:YES forKey@"stringKey4"];

Then to load it back up:

[... boolForKey:@"stringKey4"];
Tom
harrytheshark is offline   Reply With Quote
Old 01-04-2010, 04:57 PM   #3 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
jsd is on a distinguished road
Default

What is setup? If it's a UIKit object, then the .hidden property is a BOOL, but you are trying to assign a string to it. That's what's generating the warning. (Under the covers, BOOL is actually an int, and setups is a pointer, hence the "makes integer from pointer" language).

It's working because hidden is an integer, and a pointer is just a number (integer) of an address in memory. So you're saying setup.hidden = 1627362736 (or some other big number) which works.

If you want to store a BOOL in NSUserDefaults use setBool:forKey:
jsd is offline   Reply With Quote
Old 01-04-2010, 05:02 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
Vladdmeir is on a distinguished road
Default

Quote:
Originally Posted by harrytheshark View Post
Try using
Code:
[... setBool:YES forKey@"stringKey4"];

Then to load it back up:

[... boolForKey:@"stringKey4"];
Tom
I see where to put the loading code, but I'm not quite sure where in
Code:
setups = [[NSString alloc] initWithFormat:@"YES"];
		
		setup.hidden = setups;
		
		NSUserDefaults *stringDefault2 = [NSUserDefaults standardUserDefaults];
		[stringDefault2 setObject:setups forKey:@"stringKey4"];
i put
Code:
[... setBool:YES forKey@"stringKey4"];

Sorry to be a bother
Vladdmeir is offline   Reply With Quote
Old 01-04-2010, 05:05 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Completely replace:
Code:
setups = [[NSString alloc] initWithFormat:@"YES"];
		
NSUserDefaults *stringDefault2 = [NSUserDefaults standardUserDefaults];
[stringDefault2 setObject:setups forKey:@"stringKey4"];
Also, like jsd said, the hidden property is a BOOL, so "setups" should be a BOOL not an NSString.

Tom
harrytheshark is offline   Reply With Quote
Old 01-04-2010, 05:07 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
Vladdmeir is on a distinguished road
Default

Quote:
Originally Posted by harrytheshark View Post
Completely replace:
Code:
setups = [[NSString alloc] initWithFormat:@"YES"];
		
NSUserDefaults *stringDefault2 = [NSUserDefaults standardUserDefaults];
[stringDefault2 setObject:setups forKey:@"stringKey4"];
Also, like jsd said, the hidden property is a BOOL, so "setups" should be a BOOL not an NSString.

Tom
So then to make it a BOOL do I just put
Code:
setups = [[BOOL alloc]initWithFormat:@"YES"];
?

Sorry for being stupid
Vladdmeir is offline   Reply With Quote
Old 01-04-2010, 05:10 PM   #7 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

No, no.
You would just use:
Code:
BOOL setups = YES;
You should really learn the fundamentals of programming before you start on a full project.

Tom
harrytheshark is offline   Reply With Quote
Old 01-04-2010, 05:12 PM   #8 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
Vladdmeir is on a distinguished road
Default

Quote:
Originally Posted by harrytheshark View Post
No, no.
You would just use:
Code:
BOOL setups = YES;
You should really learn the fundamentals of programming before you start on a full project.

Tom
Ahh, of course, sorry.
Usually I'm better than this but I'm just so 'out of it' today if you get my drift... xD

Last edited by Vladdmeir; 01-04-2010 at 05:15 PM.
Vladdmeir is offline   Reply With Quote
Reply

Bookmarks

Tags
default, nsuser, nsuserdefault, problem

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: 344
16 members and 328 guests
akacaj, alexP, ClerurcifeDer, Domele, Duncan C, givensur, GraffitiCircus, guusleijsten, JmayLive, michelle, NetGuru, NSString, Paul Slocum, Punkjumper, Sloshmonster, soohyun
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

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