【发布时间】:2014-11-26 07:36:14
【问题描述】:
我正在使用 theos 创建一个调整,将“滑动解锁”文本更改为自定义字符串
在我的 Tweak.xm 中:
%hook SBLockScreenView
- (void)setCustomSlideToUnlockText:(id)unlockText {
NSString *settingsPath = @"/var/mobile/Library/Preferences/com.motion.tweak~prefs.plist";
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
NSString *text = [prefs objectForKey:@"text"];
BOOL enabled = [prefs objectForKey:@"enabled"];
if([text isEqualToString:@""] || text == nil || ![enabled]) {
%orig(unlockText);
}
else if ([enabled]) {
unlockText = text;
%orig(unlockText);
}
}
%end
当我尝试 make package 时返回一个错误:
error: cannot initialize a variable of type 'BOOL' (aka 'signed char')
with an rvalue of type 'id'
BOOL enabled = [prefs objectForKey:@"enabled"];
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
【问题讨论】:
-
我相信 [pref objectForKey:@"enabled"] 将返回一个 NSNumber* 类型。
-
Tim 是正确的,因此将其更改为 [[prefs objectForKey:@"enabled"] boolValue]
-
@TimEdwards @ŃikeKamstra 谢谢你们,当我尝试制作包时,我现在返回一个新错误:
Tweak.xm:41:58: error: expected identifier if([text isEqualToString:@""] || text == nil || ![enabled]) { ^ Tweak.xm:46:18: error: expected identifier else if ([enabled]) { ^ -
我把它改成答案。
标签: objective-c boolean objective-c++ theos tweak