为什么 NSString getCharacters 在 xcode 中不起作用? [英] Why doesn't NSString getCharacters work in xcode?

查看:49
本文介绍了为什么 NSString getCharacters 在 xcode 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-(void)myFunction {

        unichar myBuffer[5];
        NSRange range = {0, 3};
        NSString *string = [NSString alloc];
        string = @"123";
        [string getCharacters:myBuffer :range];
}

收到警告

!NSString 可能没有响应'-getCharacters::'

! NSString may not respond to '-getCharacters::'

然后在我运行它时执行 SIGABRT.为什么?????或者更好的是我怎样才能让它工作?

then does a SIGABRT when I run it. Why????? Or better yet how can I get it to work?

推荐答案

要使用 getCharacters:range:,请编写这行代码:

To use getCharacters:range:, write this line of code:

[string getCharacters:myBuffer range:range];

在 Objective-C 中,方法名称按参数(源自 Smalltalk 传统的特性)分开.因此,您的原始代码试图发送一条基本上名为 getCharacters: : 的消息,但未找到该消息.更正后的版本发送消息 getCharacters: range:.

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 message getCharacters: range:.

getCharacters:myBuffer 构造表示 getCharacters:range: 的第一个参数是 myBuffer.类似地,range:range 构造表示第二个参数是名为 rangeNSRange.

The getCharacters:myBuffer construct says that the first argument to getCharacters:range: is myBuffer. Similarly, the range:range construct says the second argument is your NSRange named range.

这篇关于为什么 NSString getCharacters 在 xcode 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆