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 09-22-2011, 08:25 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 176
Rifts is on a distinguished road
Default Can't check NSNumber for null

I have an NSNumber I need to check if there is a value for it and if not set it to 0.

This is what I'm trying with no success.

Code:
if (theScore == nil) {
      theScore = 0;
}
Code:
if (theScore < 0) {
      theScore = 0;
}
Code:
if (theScore == NULL) {
      theScore = 0;
}
no matter what I try it won't set to 0 just stays (null)
Rifts is offline   Reply With Quote
Old 09-22-2011, 09:06 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Because you can't create an NSNumber object using = x.

Code:
if (theScore == nil) {
theScore = [NSNumber numberWithInt:0];
}
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 09-22-2011, 09:34 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 176
Rifts is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Because you can't create an NSNumber object using = x.

Code:
if (theScore == nil) {
theScore = [NSNumber numberWithInt:0];
}
you can't compare NSNumber to nil is the warning im getting
Rifts is offline   Reply With Quote
Old 09-22-2011, 09:52 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

An NSNumber is an object and therefor can be compared against nil.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 09-22-2011, 10:12 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 176
Rifts is on a distinguished road
Default

ok guess the problem is this

I have an NSNumber *totalScore = 0 I'm trying to add it to an NSInterger so I'm converting it like this
NSInteger oldScore = [totalScore intValue];

but when I NSLog oldScore I get (null)

why isn't it 0?

ok well I fixed it, instead of using NSInterger I just did int oldScore
Rifts is offline   Reply With Quote
Old 09-22-2011, 10:18 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

You can't create NSNumber objects using = x. That only works for primitive types. You need to create an NSNumber object using [NSNumber numberWithInt:x];
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele 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: 390
14 members and 376 guests
7twenty7, eski, EvilElf, HemiMG, iOS.Lover, jarv, n00b, pbart, Pudding, sacha1996, Sami Gh, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

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