Skip to content

Instantly share code, notes, and snippets.

@trojanfoe
Last active December 22, 2015 03:29
Show Gist options
  • Save trojanfoe/6411009 to your computer and use it in GitHub Desktop.
Save trojanfoe/6411009 to your computer and use it in GitHub Desktop.
NSMutableArray from NSArray copy
#import <Foundation/Foundation.h>
int main(int argc, const char **argv) {
@autoreleasepool {
NSMutableArray *mutableArray;
NSString *str = @"one two three";
mutableArray = [[str componentsSeparatedByString:@" "] copy];
[mutableArray addObject:@"four"];
for (NSString *s in mutableArray) {
NSLog(@"%@", s);
}
}
return 0;
}
$ clang -o test test.m -framework Foundation
$ ./test
2013-09-02 10:32:08.365 test[10130:707] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x10b214f70
2013-09-02 10:32:08.368 test[10130:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x10b214f70'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff89501f56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff89684d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8958e1be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff894eee23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff894eec38 _CF_forwarding_prep_0 + 232
5 test 0x000000010b192ca0 main + 192
6 test 0x000000010b192bd4 start + 52
)
terminate called throwing an exceptionAbort trap: 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment