ARC 不允许将非 Objective-C 指针类型 'SEL' 隐式转换为 'NSString * _Nonnull'

Implicit conversion of a non-Objective-C pointer type 'SEL' to 'NSString * _Nonnull' is disallowed with ARC

我阅读了其他 5 篇相关文章questions with the same error or 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 以及 error/warning 在这里的含义。

我还收到警告:Incompatible pointer types sending 'SEL' to parameter of type


编辑: 这个问题基本上是 What's the difference between a method and a selector?

的重复

您只能将选择器传递给采用选择器的方法。 fileExistsAtPath: 采用 NSString *,而不是 SEL

您似乎想将 getDBFile 的 return 值传递给 fileExistsAtPath:,而不是 getDBFile 的选择器。

如果是这样,只需调用 getDBFile 而不是使用其选择器:

BOOL isDatabaseInCache = [fileManager fileExistsAtPath:[self getDBFile]];