升级到 xcode 4.6 和 iOS 6.1 后出错“用作前一个参数的名称而不是选择器的一部分”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14577478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error after upgrading to xcode 4.6 and iOS 6.1 "used as the name of the previous parameter rather than as part of the selector"
提问by snksnk
After updating to xcode 4.6 and ios6.1, I get this new error "'objectType' used as the name of the previous parameter rather than as part of the selector". I get this multiple times. Any ideas?
更新到 xcode 4.6 和 ios6.1 后,我收到这个新错误“‘objectType’用作前一个参数的名称,而不是作为选择器的一部分”。我多次得到这个。有任何想法吗?
PS: The method that it get displayed is a custom one for reverse geocoding.
PS:它显示的方法是用于反向地理编码的自定义方法。
-(void) getAddress: (NSString *) objectType: (CLLocationCoordinate2D) objectCoordinate
回答by iDev
It says that objectType
is the name of the NSString
object in your method and not part of the method name and it should not be used as objectType: (CLLocationCoordinate2D) objectCoordinate
which normally denotes a part of method name.
它说这objectType
是NSString
您的方法中对象的名称,而不是方法名称的一部分,不应将其用作objectType: (CLLocationCoordinate2D) objectCoordinate
通常表示方法名称的一部分。
Ideally you should change,
理想情况下你应该改变,
-(void) getAddress: (NSString *) objectType: (CLLocationCoordinate2D) objectCoordinate
to a more readable,
更易读,
-(void) getAddress:(NSString *)objectType coordinate:(CLLocationCoordinate2D) objectCoordinate;
The above error can also be fixed by putting a space between objectType
and next param in method definition(For eg:- -(void)getAddress:(NSString *)objectType : (CLLocationCoordinate2D)objectCoordinate
). Note the space after objectType
.
上述错误也可以通过objectType
在方法定义中的下一个参数和下一个参数之间放置一个空格来修复(例如:-)-(void)getAddress:(NSString *)objectType : (CLLocationCoordinate2D)objectCoordinate
。注意后面的空格objectType
。
Update:
更新:
To answer the question in comments you can use the below line to suppress these warnings:
要回答评论中的问题,您可以使用以下行来取消这些警告:
#pragma clang diagnostic ignored "-Wmissing-selector-name"
Add this in your pch file. I am not sure if this will work for your case where it comes from library but you can try it out. Check this clang-trunkfor more details.
将此添加到您的 pch 文件中。我不确定这是否适用于您来自图书馆的情况,但您可以尝试一下。查看此 clang-trunk以获取更多详细信息。
回答by Alex Gray
It's all about the spacing, darling... as @Martin R said re: this, debateably BETTER question...
这都是关于间距的,亲爱的......正如@Martin R所说:这个,可以辩论的更好的问题......
"It is sufficient to insert a space before the second parameter."
“在第二个参数前插入一个空格就足够了。”
Sufficient meaning, here, that Xcode shuts the hell up..
足够的意思,在这里,Xcode 关闭了地狱..
In the spirit of that odd piece of syntatic trivia... here's my favorite Cocoa header file, EVER. and yes, those are all valid method names, hehe.
本着那些奇怪的语法琐事的精神......这是我最喜欢的 Cocoa 头文件,EVER。是的,这些都是有效的方法名称,呵呵。
@interface NSString (JASillyString)
-:a;
-:a :b;
-:a :b :c;
-:a :b :c :d;
-:a :b :c :d :e;
-:a :b :c :d :e :f;
-:a :b :c :d :e :f :g;
-:a :b :c :d :e :f :g :h;
-:a :b :c :d :e :f :g :h :i;
-:a :b :c :d :e :f :g :h :i :j;
-:a :b :c :d :e :f :g :h :i :j :k;
-:a :b :c :d :e :f :g :h :i :j :k :l;
-:a :b :c :d :e :f :g :h :i :j :k :l :m;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s :t;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s :t :u;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s :t :u :v;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s :t :u :v :w;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s :t :u :v :w :x;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s :t :u :v :w :x :y;
-:a :b :c :d :e :f :g :h :i :j :k :l :m :n :o :p :q :r :s :t :u :v :w :x :y :z;
@end
回答by Hyman Patoliya
Your method is declaring the selector With spaces,
你的方法是用空格声明选择器,
-(NSString *)testMethod:(double)price :(BOOL)flag;
Note mention .h and .m both are same and equal spaces
注意提到 .h 和 .m 都是相同且相等的空格
When retrive methode, that time careful about method and its arguments. like [self testMethod:4.5(space):TRUE];
检索方法时,请注意方法及其参数。喜欢 [self testMethod:4.5(space):TRUE];