Skip to content

Instantly share code, notes, and snippets.

@ezura
Last active August 29, 2015 14:26
Show Gist options
  • Save ezura/338ca3a8970405257d11 to your computer and use it in GitHub Desktop.
Save ezura/338ca3a8970405257d11 to your computer and use it in GitHub Desktop.
クラスに [], {} を実装する ref: http://qiita.com/ezura/items/dd4ff9b0ae2a1afa3bb3
// id obj = custom[@1];
- (id)objectForKeyedSubscript:(id)key;
// custom[@1] = @0;
- (void)setObject:(id)anObject forKeyedSubscript:(id <NSCopying>)aKey;
- (id)objectForKeyedSubscript:(id)key
{
return @"10";
}
- (void)setObject:(id)anObject forKeyedSubscript:(id <NSCopying>)aKey
{
...
}
CustomClass *custom = [CustomClass new];
id arrayObj = custom[1];
custom[0] = @10;
id dictObj = custom[@1];
custom[@1] = @0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment