iOS-Bug: copyWithZone:

File *f = [[File alloc] init];
    f.fileName = @"wwww";
    f.bytes = 0;
    NSArray *arr1 = [NSArray arrayWithObjects:f, nil];
    NSMutableArray *arr2 = nil;
    
    //arr2 = [[NSMutableArray alloc] initWithArray:arr1]; /* retain f */
    //arr2 = [NSMutableArray arrayWithArray:arr1];      /* retain f */
    //[arr2 addObject:[arr1 firstObject]];              /* retain f */
    
    //arr2 = [NSMutableArray arrayWithObjects:[f copy], nil];           /* f needs implements -copyWithZone: */
    //arr2 = [[NSMutableArray alloc] initWithArray:arr1 copyItems:YES]; /* f needs implements -copyWithZone:  */
    
    ((File *)arr2[0]).fileName = @"arr2";
    ((File *)arr2[0]).bytes = 100;
    
    NSLog(@"Arr1: %@", ((File *)arr1[0]).fileName);
    NSLog(@"Arr2: %@", ((File *)arr2[0]).fileName);
    NSLog(@"File: %@", f.fileName);
    
    
    NSLog(@"Arr1: %lld", ((File *)arr1[0]).bytes);
    NSLog(@"Arr2: %lld", ((File *)arr2[0]).bytes);
    NSLog(@"File: %lld", f.bytes);

你可能感兴趣的:(iOS-Bug: copyWithZone:)