我正在检索像这样的Parse对象:
PFObject *countObject=[[PFUser currentUser] objectForKey:@"count"];
count为“5”(在Parse.com的控制面板上设置)。如何将此对象转换为int?想做什么
int x = countObject;
答案 0 :(得分:3)
我假设
返回的值[[PFUser currentUser] objectForKey:@"count"];
是NSNumber,因此您可以使用intValue方法NSNumber reference
id num = [[PFUser currentUser] objectForKey:@"count"]
int x = [num intValue];
如果您对返回值有疑问,可以使用:
NSLog(@"%@", [[[PFUser currentUser] objectForKey:@"count"] class]);
答案 1 :(得分:0)
尝试:
int x =[countObject integerValue];
答案 2 :(得分:0)
检查课程类型以避免将来出现问题。
Class numberClass = [NSNumber class];
id countObject = [[PFUser currentUser] objectForKey:METagCount];
if ([countObject isKindOfClass:numberClass])
{
NSNumber *count = (NSNumber *) countObject;
int x = filesize.integerValue;
}