• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AddressBook Record (Group/Person) ID: What's the best way to store ID in a NSDictionary?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AddressBook Record (Group/Person) ID: What's the best way to store ID in a NSDictionary?


  • Subject: Re: AddressBook Record (Group/Person) ID: What's the best way to store ID in a NSDictionary?
  • From: Fritz Anderson <email@hidden>
  • Date: Fri, 15 Aug 2008 11:14:38 -0500

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@hidden)

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:
This email sent to email@hidden


References: 
 >AddressBook Record (Group/Person) ID: What's the best way to store ID in a NSDictionary? (From: "Lee, Frederick" <email@hidden>)

  • Prev by Date: Re: Changing NSTextFieldCells' editing appearance?
  • Next by Date: Re: Question about directory for Application Caches
  • Previous by thread: AddressBook Record (Group/Person) ID: What's the best way to store ID in a NSDictionary?
  • Next by thread: Why does Core Data retain an object when one of that object's attributes is changed?
  • Index(es):
    • Date
    • Thread