int NSInteger NSNumber

本文探讨了在不同处理器架构中使用NSInteger而非int或long的原因。当代码可能运行于未知架构时,使用NSInteger可以确保获得最大的整数类型,在32位系统中为int,在64位系统中为long。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

look down

 

 #if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif

 

you usually want to use NSInteger when you don't konw what kind of processor architechture your code might run on,so you may for som reason, want the largest possible int type, which on 32 bit system is just an int, whileon a 64-bit system it's a long;

so i 'd stick with using NSInteger instead of int / long Unless you specifically require them;

 

 

2013 12-13

{ NSString *lockString = @"剧集解锁状态"; for (int i= 0; i < infoModel.lockStatusArray.count; i++) { NSNumber *status = infoModel.lockStatusArray[i]; lockString = [lockString stringByAppendingFormat:@"%@%@集-%@", i == 0 ? @":":@",", @(i+1), status.intValue == 1 ? @"已解锁":@"未解锁"]; } NSLog(@"[短剧解锁开始回调]%@", lockString); if ([extraInfo valueForKey:@"isContinuityUnlock"]) { //连续解锁逻辑 NSInteger current_unlock_episode = [[extraInfo valueForKey:@"current_unlock_episode"] integerValue]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"看广告解锁" message:[NSString stringWithFormat:@"看一个激励广告解锁%ld集,\n 再看一次广告解锁%@集-%@集", self.unlockCountPerAD, @(current_unlock_episode), @(current_unlock_episode + self.unlockCountPerAD)] preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { DJXPlayletUnlockModel *unlockInfo = [[DJXPlayletUnlockModel alloc] init]; unlockInfo.cancelUnlock = YES; unlockInfo.unlockModeType = DJXPlayletUnlockModeType_Continuous; unlockInfoHandler(unlockInfo); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"看广告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { DJXPlayletUnlockModel *unlockInfo = [[DJXPlayletUnlockModel alloc] init]; unlockInfo.playletId = infoModel.shortplay_id; unlockInfo.unlockEpisodeCount = self.unlockCountPerAD; unlockInfo.unlockModeType = DJXPlayletUnlockModeType_Continuous; unlockInfoHandler(unlockInfo); }]]; [self.presentedViewController presentViewController:alert animated:YES completion:nil]; } else { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"看广告解锁" message:[NSString stringWithFormat:@"看一个激励广告解锁%ld集", self.unlockCountPerAD] preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { DJXPlayletUnlockModel *unlockInfo = [[DJXPlayletUnlockModel alloc] init]; unlockInfo.cancelUnlock = YES; unlockInfo.unlockModeType = self.unlockModeType; unlockInfoHandler(unlockInfo); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"看广告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { DJXPlayletUnlockModel *unlockInfo = [[DJXPlayletUnlockModel alloc] init]; unlockInfo.playletId = infoModel.shortplay_id; unlockInfo.unlockEpisodeCount = self.unlockCountPerAD; unlockInfo.unlockModeType = self.unlockModeType; unlockInfoHandler(unlockInfo); }]]; [self.presentedViewController presentViewController:alert animated:YES completion:nil]; } } 帮我转成swift的写法
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值