Why doesn't NSString getCharacters work in xcode?
-(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?
To use getCharacters:range:
, write this line of code:
[string getCharacters:myBuffer range: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:
.
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
.
精彩评论