Using NSCoding with ABRecordRefs?

Discussion in 'iOS Programming' started by Littleodie914, Jun 29, 2008.

  1. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #1
    Howdy fellow programmers! :)

    I've got an app on the iPhone that integrates with Apple's Address Book, but I'm wondering if there's a way to save/load the ABRecordRef's to/from disk. I'm currently doing the following:

    Code:
    # For the initWithCoder:
    self.people = (CFMutableArrayRef)([[NSMutableArray alloc] initWithArray:[coder decodeObjectForKey:@"AssignmentPeople"]]);
    
    #For the encodeWithCoder
    NSArray *arrayToSave = (NSArray *)self.people;	
    [coder encodeObject:arrayToSave forKey:@"AssignmentPeople"];
    Since CFArrays and NSArrays are toll-free bridged, the array conversion isn't an issue. I'm getting this error when writing to disk though, which leads me to believe there's an issue serializing the individual ABRecordRef's inside:

    Code:
    2008-06-29 22:07:30.863 iProcrastinate Mobile[2265:20b] *** -[NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x1a9930
    2008-06-29 22:07:30.870 iProcrastinate Mobile[2265:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x1a9930'
    From reading that error message, does that sound like it's the issue? It's the only CFType-ish thing that I'm encoding, so I can't think of anything else that might be causing the problem.

    If it is the problem, what other way should I be using to save those record types? :confused:
     
  2. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #2
    Hmm... I had a bit more time to debug it this morning, and I'm becoming more and more sure that's the problem, based on the debugger trace when the error occurred. So I think my question still is, how can you encode/decode CFType objects? I've googled all over the place, and there's very little documentation. :(
     

    Attached Files:

  3. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #3
    I'm at work right now, but I think when I get home I'm going to switch over from storing the actual ABPersonRef's to storing the RecordID's. That way I can avoid all the complicated data management, and then if a person changes outside of the app, the changes will be reflected inside. :)
     

Share This Page