修改构建设置以编译SQLCipher后,FMDB类出现ARC错误



我遵循了在iOS设备上使用位于此处的二进制文件编译SQLCipher的教程:http://sqlcipher.net/sqlcipher-binaries-ios-and-osx/

我对构建设置做了一些更改,添加了头搜索路径和C标志。然后,在测试了sqlcipher的编译后,我在二进制文件中没有得到任何错误,但以前FMDB中不存在的错误开始显示如下:

FMDatabaseAdditions.m:137:19:函数"NSFileTypeForHFSTypeCode"的隐式声明在C99`中无效

FMDatabaseAdditions.m:137:19:ARC `不允许将"int"隐式转换为"NSString*">

FMDatabaseAdditions.m:137:15:初始化"NSString*__strong"时使用类型为"int"`的表达式的整数到指针转换不兼容

FMDatabaseAdditions.m:158:96:"NSUInteger"类型的值不应用作格式参数;将显式强制转换添加到"unsigned long",而不是`

FMDatabaseAdditions.m:161:28:函数"NSHFSTypeCodeFromFileType"的隐式声明在C99`中无效

当您在项目中使用目标时会发生此错误。NSFileTypeForHFSTypeCode仅在针对Mac OS目标编译项目时才需要,如果目标是iPhone,则不应使用。事实上,在新版本的XCode上,即使您的项目以iPhone为目标,似乎也会出现错误。旧答案:

因此,我们必须重写applicationIDString实现并放置条件标志:

#if TARGET_OS_MAC && !TARGET_OS_IPHONE
- (NSString*)applicationIDString {
NSString *s = NSFileTypeForHFSTypeCode([self applicationID]);
assert([s length] == 6);
s = [s substringWithRange:NSMakeRange(1, 4)];

return s;
}
#endif

如果TARGET_OS_MAC的条件将不会取代的需要!因为TARGET_OS_IPHONE实际上是TARGET_OS_MAC的变体。因此,为了避免编译错误,请添加#if TARGET_OS_MAC&amp!TARGET_OS_IPHONE

同样在代码的那部分下面:

- (void)setApplicationIDString:(NSString*)s {
if ([s length] != 4) {
NSLog(@"setApplicationIDString: string passed is not exactly 4 chars long. (was %ld)", [s length]);
}
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
[self setApplicationID:NSHFSTypeCodeFromFileType([NSString stringWithFormat:@"'%@'", s])];
#endif
}

新答案:

我更新了代码并重新排列了方法,以便根据FMDatabaseAdditions中的范围(条件)进行更多分组。m

#if SQLITE_VERSION_NUMBER >= 3007017
- (uint32_t)applicationID {
uint32_t r = 0;
FMResultSet *rs = [self executeQuery:@"pragma application_id"];
if ([rs next]) {
r = (uint32_t)[rs longLongIntForColumnIndex:0];
}
[rs close];
return r;
}
- (void)setApplicationID:(uint32_t)appID {
NSString *query = [NSString stringWithFormat:@"pragma application_id=%d", appID];
FMResultSet *rs = [self executeQuery:query];
[rs next];
[rs close];
}

#if TARGET_OS_MAC && !TARGET_OS_IPHONE
- (NSString*)applicationIDString {
NSString *s = NSFileTypeForHFSTypeCode([self applicationID]);
assert([s length] == 6);
s = [s substringWithRange:NSMakeRange(1, 4)];

return s;
}
- (void)setApplicationIDString:(NSString*)s {
if ([s length] != 4) {
NSLog(@"setApplicationIDString: string passed is not exactly 4 chars long. (was %ld)", [s length]);
}
[self setApplicationID:NSHFSTypeCodeFromFileType([NSString stringWithFormat:@"'%@'", s])];
}

#endif
#endif

为了避免其他警告,我修改了FMDatabaseAdditions。h

#if SQLITE_VERSION_NUMBER >= 3007017
///-----------------------------------
/// @name Application identifier tasks
///-----------------------------------
/** Retrieve application ID
@return The `uint32_t` numeric value of the application ID.
@see setApplicationID:
*/
- (uint32_t)applicationID;
/** Set the application ID
@param appID The `uint32_t` numeric value of the application ID.
@see applicationID
*/
- (void)setApplicationID:(uint32_t)appID;
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
/** Retrieve application ID string
@return The `NSString` value of the application ID.
@see setApplicationIDString:
*/

- (NSString*)applicationIDString;
/** Set the application ID string
@param string The `NSString` value of the application ID.
@see applicationIDString
*/
- (void)setApplicationIDString:(NSString*)string;
#endif
#endif

它看起来是FMDB中的一个错误(https://github.com/ccgus/fmdb/issues/163)-有问题的代码仅用于在OSX中编译。

最新更新