我遵循了使用位于此处的二进制文件在 iOS 设备上编译 SQLCipher 的教程:http://sqlcipher.net/sqlcipher-binaries-ios-and-osx/
我对build设置进行了多项更改,添加了 header 搜索路径和 cflags。然后在测试了 sqlcipher 的编译后,二进制文件没有出现任何错误,但是 FMDB 之前不存在的错误开始显示如下:
FMDatabaseAdditions.m:137:19: Implicit declaration of function 'NSFileTypeForHFSTypeCode' is invalid in C99`
FMDatabaseAdditions.m:137:19: Implicit conversion of 'int' to 'NSString *' is disallowed with ARC`
FMDatabaseAdditions.m:137:15: Incompatible integer to pointer conversion initializing 'NSString *__strong' with an expression of type 'int'`
FMDatabaseAdditions.m:158:96: Values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead`
FMDatabaseAdditions.m:161:28: Implicit declaration of function 'NSHFSTypeCodeFromFileType' is invalid in 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_IPHONE 实际上是 TARGET_OS_MAC 的变体。所以为了避免编译错误,添加#if TARGET_OS_MAC && !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
关于ios - 更改build设置以编译 SQLCipher 后 FMDB 类出现 ARC 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21111794/