【发布时间】:2016-04-25 17:19:42
【问题描述】:
我阅读了 5 个其他相关的 questions 相同的错误或 syntax。据我了解,与我的问题无关。
-(void) createCopyOfDBIfNeeded{
NSFileManager *fileManager= [NSFileManager defaultManager];
BOOL isDatabaseInCache = [fileManager fileExistsAtPath:@selector(getDBFile)];
if (isDatabaseInCache) {
return;
}
}
//getDBFile方法:
-(NSString *) getDBFile {
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString * DBPath = [paths firstObject];
NSString * DBFile = [DBPath stringByAppendingPathComponent:@"productDBFile.db"];
return DBFile;
}
似乎该错误与@selector(getDBFile) 有关。
如果我使用 [self getDBFile] 代替一切正常,但我想了解如何以及在何处适当地使用 @selector 以及错误/警告在这里的含义。
我也收到警告:Incompatible pointer types sending 'SEL' to parameter of type
编辑:这个问题基本上是What's the difference between a method and a selector?的副本
【问题讨论】:
-
您似乎不知道选择器是什么,并且可能对函数以及如何调用它们了解甚少。也许一个好的 Objective-C 入门是为了。
-
@asma22 请注意,Objective-C 中的方法永远不应以
get为前缀,除非它们遵循通过参数通过引用返回内容的非常特定的模式。 (常见的混淆点——欢迎使用该语言并玩得开心!)。 -
@bbum (sensei) 在一次排版聚会上有人告诉我最好避免使用
--,而应该使用Em Dash(—) 即Ctrl + shift + -:]。感谢您的欢迎 -
@asma22 哈!你们这些年轻人和你们新奇的非 7 位字符。 :) 说真的,objc 中的 setter/getter 对是 always
thing和setThing:。一个只读的 getter 就是thing。遵循约定还使用@property(readonly) NSString *thing;just work。
标签: ios objective-c xcode selector