ios - 隐式转换在制作应用时将整数精度'NSUInteger'(aka'unsigned long')转换为'int'吗?

标签 ios objective-c

我正在编码,并遇到了这个问题。

我不明白为什么会这样,我需要帮助,有人可以帮忙吗? :)

- (void)viewDidLoad
{
Start = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
Bottom1.hidden = YES;
Bottom2.hidden = YES;
Bottom3.hidden = YES;
Bottom4.hidden = YES;
Bottom5.hidden = YES;
Bottom6.hidden = YES;
Bottom7.hidden = YES;
Top1.hidden = YES;
Top2.hidden = YES;
Top3.hidden = YES;
Top4.hidden = YES;
Top5.hidden = YES;
Top6.hidden = YES;
Top7.hidden = YES;

Heli.center = CGPointMake(48, 145);

HighScore = [[NSUserDefaults standardUserDefaults] integerForKey:@"HighScoreSaved"]; < issue HERE

Intro3.text = [NSString stringWithFormat:@"High Score: %i", HighScore];

最佳答案

integerForKey返回NSUInteger值(又名无符号长)。我假设您的HighScore变量是一个int,其字节数少于一个long。尝试转换为int:

HighScore = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"HighScoreSaved"];

关于ios - 隐式转换在制作应用时将整数精度'NSUInteger'(aka'unsigned long')转换为'int'吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22951810/

相关文章:

ios - 如何获取导航栏的高度

ios - Firebase 重置密码问题

iphone - 像 Instagram 一样的照片效果

ios - Xcode 9.2 : missing required architecture arm64 in file/. ......./libPaymentsSDK.a(2 片)

ios - 应用程序如何从苹果商店获取更新?

ios - 按下取消按钮时隐藏搜索栏,并调整导航栏的大小

ios - 在 UIPickerView 上选择后显示整个数字值?

ios - 在 Swift 扩展中实现 didRegisterForRemoteNotificationsWithDeviceToken 不起作用

ios - 在 Xcode 6.1 及更高版本中创建项目时,屏幕在 iOS 7 中缩小

ios - Objective-C : Dynamic message in info. plist