Search Results

Search found 1 results on 1 pages for 'user392412'.

Page 1/1 | 1 

  • const keyword in Objective-c

    - by user392412
    int main(int argc, char *argv[]) { @autoreleasepool { const int x = 1; const NSMutableArray *array1 = [NSMutableArray array]; const NSMutableString *str1 = @"1"; NSString * const str2 = @"2"; // x = 2; compile error [array1 addObject:@"2"]; // ok // [str1 appendString:@"2"]; // runtime error // Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:' // str2 = @"3"; compile error } } my Question is Why array1 addObject is legal and why str1 appendString is forbidden?

    Read the article

1