iOS sigbart中止崩溃

iOS sigbart中止崩溃,ios,objective-c,nsmutablestring,Ios,Objective C,Nsmutablestring,我在以下方法中遇到随机崩溃: - (void) addLineToVCard:(NSMutableString **)vCard forKey:(NSString *)key setValue:(NSString *)value { [*vCard appendString:[NSString stringWithFormat:@"%@:%@\r\n", key, value]]; } 我称之为: NSMutableString* vCard = [NSMutableStri

我在以下方法中遇到随机崩溃:

- (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

不相关,但是为什么要将
nsstringwithformat
NSMutableString
一起使用呢?只需使用
appendFormat
我没有从您的代码中得到任何崩溃。刚刚复制并粘贴了你的代码,它工作得很好。@Gagan_,你说得对。这是随机的,我无法复制。这是我从crashlytics那里得到的日志。所以我想知道这是什么时候失败的。你在Crashlytics日志中没有得到任何行号吗?@Gagan_iOS,它是:3009,这是[*vCard appendString:[NSString stringWithFormat:@“%@:%@\r\n”,键,值]];然后去掉
stringWithFormat
。只需执行以下操作:
[vCard appendFormat:@“%@:%@\r\n”,键,值]@rmaddy,是的,同意你的意见。我按照你说的更新了答案。