On 14 Aug 2008, at 1:16 PM, Lee, Frederick wrote:

I tried to convert the integer into a pointer (via casting).
Like this:

NSInteger myID = ABRecordGetRecordID(myABGroup);
[myDict setObject:(NSInteger)myID forKey:groupName];

But I get a compiler warning about the pointer vs integer.

Must I wrap the AB unique key into a NS Object first?

1) Casting an NSInteger to NSInteger isn't a cast at all.

2) NSInteger is a typedef for a plain-old-data type (like int, short, or long). It isn't a pointer and must not be treated as one.

3) You refer to "myDict" as an NSDictionary. You mean NSMutableDictionary. NSDictionary, being immutable, doesn't recognize setObject:forKey:, and you'll get compiler warnings.

4) Re-examine the declaration of setObject:forKey:, either in the header or in the documentation. Both parameters are (id), a pointer type for an Objective-C object. Given the semantics of the method (the object is retained, the key is copied), they have to conform to the <NSObject> and <NSCopying> protocols, respectively. So for the purpose of your question, yes, the setObject: parameter has to be of a subclass of NSObject or NSProxy.

5) To store an integer value in a Cocoa collection, you have to create an NSNumber object containing the integer's value, such as by + [NSNumber numberWithInt:]. (Or, in 10.5, given an NSInteger value, better use +[NSNumber numberWithInteger:].)

6) My perusal of the AddressBook framework docs doesn't turn up an "ABRecordGetRecordID." The closest I can find is ABRecordCopyUniqueId(), which returns a CFStringRef/NSString. Perhaps the function exists on another platform.

        — F

 --
Fritz Anderson -- Xcode 3 Unleashed: Now Available -- 
http://x3u.manoverboard.org/

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to