Encoding an NSArray of NSString objects with NSCoder

Discussion in 'iOS Programming' started by RossOliver, Aug 13, 2008.

  1. RossOliver macrumors regular

    Joined:
    Nov 6, 2006
    #1
    Hey,

    I'm trying to make a few of my classes NSCoding compliant and I am having trouble encoding arrays with:

    Code:
    - (void)encodeArrayOfObjCType:(const char *)itemType count:(NSUInteger)count at:(const void *)address
    
    I have both an array of NSString objects and an array of a custom objects. When I try and encode the NSString array using:

    Code:
    [encoder encodeArrayOfObjCType:@encode( NSString ) count:[myArray count] at:&myArray];
    
    I get the error message:

    I don't understand why NSString is not supported since it complies with the NSCoding protocol? Is there a list of supported types somewhere?

    Any help would be greatly appreciated,

    -Ross
     
  2. Taum macrumors member

    Joined:
    Jul 28, 2008
    #2
    Hi,

    I believe encodeArrayOfObjCType:count:at: encodes a *C* array of Objective-C objects. To encode an NSArray, you can simply use encodeObject:.

    Not that I'm aware of, but I'm pretty sure any object that conforms to the NSCoding protocol can be encoded with encodeObject:, so you can look up each class in the documentation to see if they conform to this protocol or not.
     
  3. RossOliver thread starter macrumors regular

    Joined:
    Nov 6, 2006
    #3

    Ah, trying to make it harder for myself :eek:

    Thanks!
     

Share This Page