user1970081
user1970081

Reputation: 21

get integer value from NSInteger

This in the function which i am implementing

-(NSString *)DeleteFolder:(NSInteger)FolderId;

In my implementation, I am creating string using FolderId

NSString *dbScript = [NSString stringWithFormat:@"Delete from Folders Where FolderId = %d",FolderId];

but I am not getting FolderId , instead of folder ID i am getting a very long integer value. Might be pointer reference.

Please tell me how to get folder id. Am I doing any thing wrong?

Upvotes: 2

Views: 4003

Answers (2)

Hussain Shabbir
Hussain Shabbir

Reputation: 15035

Try like this:-

NSInteger a=20;
NSLog(@"yourInteger=%ld",(long)a);

Upvotes: 3

user529758
user529758

Reputation:

NSInteger is not a portable type in the sense that you can never know if it's defined to int, long, long long or something else. So, the %d conversion specifier, which is exclusively for int, is not suited for printing an NSInteger. More precisely, its usage will result in undefined behavior. You will need to do an explicit typecast:

NSLog(@"Folder ID: %lld", (long long)FolderID);

(I used long long because that's the longest possible standard integer type.)

Upvotes: 4

Related Questions