redribben icon

decode/encode

redribben | PRO | 11/21/15 11:43:06 PM UTC | 0 ⭐ | 7745 👁️ | Never ⏰ | []
Objective C |

0 B

|

None

|

0 👍

/

0 👎

- (id)initWithCoder:(NSCoder *)decoder {
    self = [super init];
    if (!self) return nil;
    NSData *data = [decoder decodeObjectForKey:@"xoSpots"];
    if (data) {
        int *temporary = (int*)[data bytes];
        for(int i = 0; i < 9; ++i) xoSpots[i] = temporary[i];
    }
    if (!data) [self startAnew];
    self.tillCatsGame = [decoder decodeIntForKey:@"count"];
    self.playersTurn = [decoder decodeIntForKey:@"turn"];
    if (!playersTurn) playersTurn = BMPlayerTypeX;
    return self;
}
 
- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:[NSData dataWithBytes:(void*)xoSpots length:9*sizeof(int)] forKey:@"xoSpots"];
    [encoder encodeInt:self.tillCatsGame forKey:@"count"];
    [encoder encodeInt:self.playersTurn forKey:@"turn"];
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎