嘿伙计们我正在为Instagram构建一个调整我正在添加一个名为instatroll的子偏好,类似于trolltwitter,将关注者的数量更改为用户设置的任何数字(使用PSEditTextCell)这里是我的代码到目前为止
#import <Foundation/Foundation.h>
static NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.idevicelover.InstaEnhancer.plist"];
NSNumber *chosenNumber = [NSNumber numberWithInt:999];
int number = chosenNumber;
static BOOL followerson = NO;
%hook IGUser -(void)setFollowerCount:(NSNumber*)fp8{
followerson = [[plist objectForKey:@"followerson"]boolValue];
if(followerson){
%orig(number);
}
else{
%orig;
}
}
%end
%ctor
{
NSDictionary *InstaEnhancer = [[NSDictionary alloc] initWithContentsOfFile:@"/var /mobile /Library/Preferences/com.idevicelover.InstaEnhancer.plist"];
if ([InstaEnhancer objectForKey:@"numberoffollowers"]) number = [[InstaEnhancer objectForKey:@"numberoffollowers"] intValue];
[InstaEnhancer release];
}
我在编译时收到此错误:“从不兼容的类型”int“分配给NSNumber *
答案 0 :(得分:1)
NSNumber
是一个对象。为了将它用作原始数据类型(例如int
),您必须使用适当的方法从中提取该类型的值:
NSNumber *chosenNumber = [NSNumber numberWithInt:999];
int number = [chosenNumber intValue];
此外,稍后,在这里:
number = [[InstaEnhancer objectForKey:@"numberoffollowers"] intValue];
如果此时number
是int
(我不知道这个语法不是C ++或Objective-C)那么这应该没问题。但如果number
的类型为NSNumber *
,那么您需要将调用放到intValue
:
number = [InstaEnhancer objectForKey:@"numberoffollowers"];