gpt4 book ai didi

cocoa - NSString stringWithUTF8String 附加错误

转载 作者:行者123 更新时间:2023-12-03 17:07:47 26 4
gpt4 key购买 nike

我正在尝试将一个字符数组附加到一个NSString。当我使用下面的代码时,出现此错误:

********* initialization method -initWithCharactersNoCopy:length:freeWhenDone: cannot be sent to an abstract object of class NSCFString: Create a concrete instance!

这是什么意思以及如何解决?

NSString *str =  [[NSString new] initWithString:@"Name: "];
NSString *name = [[NSString new] stringWithUTF8String:user.name];
//NSString *name = [[NSString stringWithUTF8String:seg.segname] copy]; //this also failed
str = [str stringByAppendingString:name];

最佳答案

我认为您正在寻找这样的东西:

NSString *str = @"Name: ";
NSString *name = [NSString stringWithUTF8String:user.name];
str = [str stringByAppendingString:name];

关于cocoa - NSString stringWithUTF8String 附加错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3215343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com