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 Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-06-2010, 06:41 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 6
throwd21 is on a distinguished road
Default pointer from integer without a cast

Hey guys

I'm having a problem trying to store information in userdefaults. I dont understand every forum i check shows that I'm creating storing the file correctly.

In the header file.

int *score;
@property(nonatomic) int *score;


In the Implementation file...

NSUserDefaults *gameDefaults = [NSUserDefaults standardUserDefaults];
//int a = score;
int *num = score;
[gameDefaults setInteger:num forKey:@"gameScore"];

THIS IS WHERE THE WARNING COMES IN...
WARNING ARGUMENT SETINTEGER MAKES "pointer from integer without a cast"


//[gameDefaults setObject:score forKey:@"gameScore"];
//[gameDefaults setInteger:number forKey:@"gameScore"];
[gameDefaults setObject:sound forKey:@"gameSound"];
[gameDefaults setFloat:gameLoopSpeed forKey:@"theGameLoopSpeed"];
[gameDefaults setFloat:delayGameLoopSpeed forKey:@"theDelayGameLoopSpeed"];
[gameDefaults setObject:[NSMutableString stringWithFormat:gameDifficulty] forKey:@"theGameDifficulty"];

[gameDefaults synchronize];
throwd21 is offline   Reply With Quote
Old 10-06-2010, 08:29 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 234
warmi is on a distinguished road
Default

Quote:
Originally Posted by throwd21 View Post
Hey guys

I'm having a problem trying to store information in userdefaults. I dont understand every forum i check shows that I'm creating storing the file correctly.

In the header file.

int *score;
@property(nonatomic) int *score;


In the Implementation file...

NSUserDefaults *gameDefaults = [NSUserDefaults standardUserDefaults];
//int a = score;
int *num = score;
[gameDefaults setInteger:num forKey:@"gameScore"];

THIS IS WHERE THE WARNING COMES IN...
WARNING ARGUMENT SETINTEGER MAKES "pointer from integer without a cast"


//[gameDefaults setObject:score forKey:@"gameScore"];
//[gameDefaults setInteger:number forKey:@"gameScore"];
[gameDefaults setObject:sound forKey:@"gameSound"];
[gameDefaults setFloat:gameLoopSpeed forKey:@"theGameLoopSpeed"];
[gameDefaults setFloat:delayGameLoopSpeed forKey:@"theDelayGameLoopSpeed"];
[gameDefaults setObject:[NSMutableString stringWithFormat:gameDifficulty] forKey:@"theGameDifficulty"];

[gameDefaults synchronize];

1. Why is your score variable stored as a pointer in the first place ?

2. Assuming you really need the pointer, you should do something like :

int val=*score;

[gameDefaults setInteger:val forKey:@"gameScore"];
warmi is offline   Reply With Quote
Old 10-06-2010, 08:58 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

warmi is right. You don't want a pointer. Perhaps you are so used to all Objective C variables being declared with a '*' before their name that you forgot what the '*' means. It means the variable is a pointer. All Objective C objects that inherit from NSObject are referenced by pointers, so that is why you see the '*' so much. But an integer like score is not an Objective C object. It is a primitive C variable. As such, it can be referred to directly, without the '*'.
RLScott is offline   Reply With Quote
Old 10-06-2010, 11:34 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 6
throwd21 is on a distinguished road
Default

thanks guys I appreciate it.

<<<< idiot!
throwd21 is offline   Reply With Quote
Reply

Bookmarks

Tags
nsuserdefaults, pointer without a cast, setinteger

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: 405
11 members and 394 guests
7twenty7, ChrisYates, djohnson, gmarro, hussain1982, Kirkout, Retouchable, skrew88, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

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