简体   繁体   English

Objective-C中的基本字符串操作

[英]Basic string manipulation in Objective-C

I have a method, which right now only needs to do an NSLog call: 我有一个方法,现在只需要执行NSLog调用即可:

(void)methodName:(NSString*)name {
    NSLog(@"hey there, %@", name);
}

It says " Local declaration of 'name' hides instance variable ". 它说“ Local declaration of 'name' hides instance variable ”。 What does this mean? 这是什么意思? How do I construct the string I want? 如何构造我想要的字符串?

Simply rename the argument: 只需将参数重命名:

-(void)methodName:(NSString*)nameParam {
   NSLog(@"hey there, %@", nameParam);
}

It means that you already have a variable called 'name' in your class that includes the methodName method. 这意味着您的类中已经包含一个名为“ name”的变量,其中包括methodName方法。 You might want to change it to look like this: 您可能需要将其更改为如下所示:

- (void)methodName:(NSString*)theName {
    NSLog(@"hey there, %@", theName);
}

You must be using name as a property or variable. 您必须将name用作属性或变量。 Using it as a parameter name in a method is using it twice. 在方法中使用它作为参数名称要使用两次。

Change the name of your method parameter to something else. 将方法参数的名称更改为其他名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM