Encoding an NSArray of NSString objects with NSCoder

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

  1. RossOliver macrumors regular

    Nov 6, 2006

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

    - (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:

    [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,

  2. Taum macrumors member

    Jul 28, 2008

    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

    Nov 6, 2006

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


Share This Page