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 > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-15-2010, 02:43 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 38
loddy1234 is on a distinguished road
Question Interger to NSInteger

Is there a way to convert an int to an NSInteger?

please can somone post some example code as i am new to obj c.
thanks in advance
loddy1234 is offline   Reply With Quote
Old 10-15-2010, 03:05 PM   #2 (permalink)
Banned
 
Join Date: Jul 2009
Posts: 576
Not_Appy_At_All is on a distinguished road
Default

Quote:
Originally Posted by loddy1234 View Post
Is there a way to convert an int to an NSInteger?

please can somone post some example code as i am new to obj c.
thanks in advance
Not sure if I understand your question...but,

You simply declare it.

NSInteger can hold an int value or a long value.

If the name of your variable is myInteger...then declare it like this.

Code:
NSInteger myInteger;

That will receive an "int" value.
Not_Appy_At_All is offline   Reply With Quote
Old 10-15-2010, 06:20 PM   #3 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Quote:
Originally Posted by loddy1234 View Post
Is there a way to convert an int to an NSInteger?

please can somone post some example code as i am new to obj c.
thanks in advance
Are you trying to convert one to the other and finding that it's not working, or just asking a theoretical question?
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 10-17-2010, 04:17 PM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 14
drewbert is on a distinguished road
Default

Quote:
Originally Posted by loddy1234 View Post
Is there a way to convert an int to an NSInteger?

please can somone post some example code as i am new to obj c.
thanks in advance
NSInteger is typedef'd as a long int, so you don't need to "convert" as with NSNumber (which is a complex type). For more discussion on NSInteger vs. NSNumber check out: NSNumber versus NSInteger

All of this should be cool:
Code:
int myInt = 32;

NSInteger myNSInt = myInt;

int anotherInt = myNSInt + 5;

myNSInt = anotherInt;

NSNumber *myNSNumber = [[NSNumber alloc] initWithInt:myNSInt]; //because it's an objective-c class and must be alloc'd/released

Last edited by drewbert; 10-17-2010 at 04:21 PM.
drewbert is offline   Reply With Quote
Old 01-20-2011, 12:24 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 3
morrismountain is on a distinguished road
Default

Well, I think this code will help you.
NSInteger myInteger = 42;
int myInt = myInteger;

NSInteger is nothing more than a 32/64 bit int. And also it will use the appropriate size based on what OS/platform you're running.
morrismountain is offline   Reply With Quote
Old 01-23-2011, 06:02 AM   #6 (permalink)
"Sorry, but I dont know."
 
Join Date: Dec 2009
Location: Switzerland (CH)
Age: 16
Posts: 213
mavrick3 is on a distinguished road
Default

You don't need to convert an int into an NSInteger, 'cause int is the primitive version of NSInteger. So int and NSInteger are almost the same thing. So the iOS converts it for you if it's really needed.
mavrick3 is offline   Reply With Quote
Reply

Bookmarks

Tags
convert, int, integer, nsinteger

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: 478
15 members and 463 guests
7twenty7, AlanFloyd, AppsBlogger, David-T, iAppDeveloper, imac74, Jaxen66, lovoyl, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

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