iOS sigbart 中止崩溃

iOS sigbart abort crash

我在使用以下方法时遇到随机崩溃:

- (void) addLineToVCard:(NSMutableString **)vCard forKey:(NSString *)key setValue:(NSString *)value
{
        [*vCard appendString:[NSString stringWithFormat:@"%@:%@\r\n", key, value]];

}

我称之为:

NSMutableString* vCard = [NSMutableString string];
[self addLineToVCard:&vCard forKey:@"BEGIN"   setValue:@"VCARD"];
[self addLineToVCard:&vCard forKey:@"VERSION" setValue:@"3.0"];

我做错了什么?我可以通过传递引用而不是指针对象来避免这种情况。但是我想知道这里崩溃的原因。

崩溃日志:

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x251e6c5c __pthread_kill + 8
1  libsystem_pthread.dylib        0x25290733 pthread_kill + 62
2  libsystem_c.dylib              0x2517b0ad abort + 108
3  libsystem_malloc.dylib         0x252180ad free_list_checksum_botch + 362
4  libsystem_malloc.dylib         0x252181db free_tiny_botch + 66
5  CoreFoundation                 0x255332d3 __CFStringChangeSizeMultiple + 1838
6  CoreFoundation                 0x2553178b __CFStringCheckAndReplace + 554
7  CoreFoundation                 0x25491557 -[__NSCFString appendString:] + 26
8  iPhoneHandheldACT              0x1ae7cf -[ContactDetailViewController addLineToVCard:forKey:setValue:] (ContactDetailViewController.m:3009)
9  iPhoneHandheldACT              0x1ae515 -[ContactDetailViewController assembleVCard:] (ContactDetailViewController.m:2987)
10 iPhoneHandheldACT              0x1adcbd -[ContactDetailViewController shareVCard:] (ContactDetailViewController.m:2927)
11 iPhoneHandheldACT              0x1ad351 __47-[ContactDetailViewController btnSharePressed:]_block_invoke (ContactDetailViewController.m:2813)
12 UIKit                          0x29f2cbd9 -[UIAlertController _fireOffActionOnTargetIfValidForAction:] + 68
13 UIKit                          0x29f2d283 __85-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:]_block_invoke + 30
14 UIKit                          0x29e237e3 -[UIPresentationController transitionDidFinish:] + 1230
15 UIKit                          0x29e26a85 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 192
16 UIKit                          0x29c04157 -[_UIViewControllerTransitionContext completeTransition:] + 90
17 UIKit                          0x29b11ba5 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 540
18 UIKit                          0x29b11685 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 204
19 UIKit                          0x29b1157f -[UIViewAnimationState animationDidStop:finished:] + 78
20 QuartzCore                     0x27b71689 CA::Layer::run_animation_callbacks(void*) + 252
21 libdispatch.dylib              0x250c980f _dispatch_client_callout + 22
22 libdispatch.dylib              0x250d7ba9 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1524
23 CoreFoundation                 0x2551db6d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
24 CoreFoundation                 0x2551c067 __CFRunLoopRun + 1574
25 CoreFoundation                 0x2546b229 CFRunLoopRunSpecific + 520
26 CoreFoundation                 0x2546b015 CFRunLoopRunInMode + 108
27 GraphicsServices               0x26a5bac9 GSEventRunModal + 160
28 UIKit                          0x29b3f189 UIApplicationMain + 144
29 iPhoneHandheldACT              0xcbe21 main (main.m:16)
30 libdispatch.dylib              0x25113873 (Missing)

指针的指针不是必须的,像这样:

- (void)addLineToVCard:(NSMutableString *)vCard forKey:(NSString *)key setValue:(NSString *)value
{
    [vCard appendFormat:@"%@:%@\r\n", key, value];
}

然后使用它:

NSMutableString* vCard = [NSMutableString string];
[self addLineToVCard:vCard forKey:@"BEGIN"   setValue:@"VCARD"];
[self addLineToVCard:vCard forKey:@"VERSION" setValue:@"3.0"];

结果:

(lldb) po vCard
BEGIN:VCARD
VERSION:3.0