为什么 NSString getCharacters 在 xcode 中不起作用?
-(void)myFunction {
unichar myBuffer[5];
NSRange range = {0, 3};
NSString *string = [NSString alloc];
string = @"123";
[string getCharacters:myBuffer :range];
}
收到警告
! NSString 可能不响应 到“-getCharacters::”
然后在我运行它时执行 SIGABRT。 为什么?????或者更好的是我怎样才能让它工作?
-(void)myFunction {
unichar myBuffer[5];
NSRange range = {0, 3};
NSString *string = [NSString alloc];
string = @"123";
[string getCharacters:myBuffer :range];
}
Gets warning
! NSString may not respond
to '-getCharacters::'
then does a SIGABRT when I run it.
Why????? Or better yet how can I get it to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使用
getCharacters:range:
,请编写以下代码行:在 Objective-C 中,方法名称由参数分隔(源自 Smalltalk 传统的功能)。因此,您的原始代码试图发送一条本质上名为
getCharacters: :
的消息,但未找到该消息。更正后的版本发送消息getCharacters: range:
。getCharacters:myBuffer
构造表示getCharacters:range:
的第一个参数是myBuffer
。同样,range:range
构造表示第二个参数是名为range
的NSRange
。To use
getCharacters:range:
, write this line of code:In Objective-C, method names are split up by arguments (a feature that derives from its Smalltalk heritage). So your original code was trying to send a message that's essentially named
getCharacters: :
, which isn't found. The corrected version sends the messagegetCharacters: range:
.The
getCharacters:myBuffer
construct says that the first argument togetCharacters:range:
ismyBuffer
. Similarly, therange:range
construct says the second argument is yourNSRange
namedrange
.