Advertisement
Guest User

Mutable copying

a guest
Oct 22nd, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     NSArray *items = @[@1, @2, @"Three"];
  2.     NSDictionary *d = @{@"items" : items};
  3.     NSMutableDictionary *md = [d mutableCopy];
  4.     id mitems = md [@"items"];
  5.    
  6.     NSLog (@"items %p == %p mutable items? %i", items, mitems, items == mitems);
  7.    
  8.     // fail: -[__NSArrayI addObject:]: unrecognized selector
  9.     //[mitems addObject: @"Four"];
  10.    
  11.     NSMutableDictionary *md2 =
  12.       (id)CFBridgingRelease
  13.         (CFPropertyListCreateDeepCopy (NULL, (CFPropertyListRef)d,
  14.                                        kCFPropertyListMutableContainers));
  15.    
  16.     id mitems2 = md2 [@"items"];
  17.     NSLog (@"items %p == %p mutable items? %i", items, mitems2, items == mitems2);
  18.    
  19.     // OK
  20.     [mitems2 addObject: @"Four"];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement