Store int32_t in NSDictionary

How to save a type variable int32_t(e.g. for ABPropertyID) in NSDictionary?

[NSNumber numberWithInt:...]doesn't seem to work.

thank


From the comments:

NSLog(@" %@ %@ ", [NSNumber numberWithLong:kABPersonFirstNameProperty], kABPersonFirstNameProperty);

Fingerprints: 0 (null) Any ideas?

+3
source share
4 answers

+[NSNumber numberWithInteger:]will contain a 32-bit number on all 32-bit and 64-bit systems. +[NSNumber integerValue]will get it. If you need this unsigned, you can use `` + [NSNumber numberWithUnsignedInteger:] `.

+2
source

I assume that Dave's problem is specific to kAB constants ... - I could be wrong, and in this case ignore the following :)

, , ; . , , kAB..., , ABAddressBookCreate(). :

NSLog(@" %@ %@ ", [NSNumber numberWithLong:kABPersonFirstNameProperty], kABPersonFirstNameProperty);

:

NSLog(@" %@ %d ", [NSNumber numberWithLong:kABPersonFirstNameProperty], kABPersonFirstNameProperty);

- ABAddressBookCreate():

NSLog(@"Check: %d %d %d", kABPersonFirstNameProperty,kABPersonMiddleNameProperty,kABPersonLastNameProperty);

: 0 0 0

,

: 0 6 1

+2

, NSNumber . , , , : CFDictionary ( , NSDictionary , ) NSMapTable.

+1

NSNumber .

In more complex cases, you can always use NSValue or NSData to place any type or pointer in an Objective-C object that can be stored in Cocoa collections.

int32_t myInt = 42;
NSValue *myValue = [NSValue value:&myInt withObjCType:@encode(int32_t)];
+1
source

Source: https://habr.com/ru/post/1730095/


All Articles