LoginSignup
4
4

More than 5 years have passed since last update.

デバイスが32bitなのか64bitなのかチェックする

Posted at

ポインタのサイズを調べればOK

if (sizeof(int *) == 4) {
    // 32bit
} else if (sizeof(int *) == 8) {
    // 64bit
}
// others

下のようなカテゴリを作成すれば、NSOperationQueuemaxConcurrentOperationCountや、NSManagedObjectContextの保存バッチサイズを決定するための基準に使えそうです。

// UIDevice+Hardware.h
typedef NS_ENUM(NSUInteger, DeviceArchitecture) {
    DeviceArchitectureUnknown,
    DeviceArchitecture32Bit,
    DeviceArchitecture64Bit,
};

@interface UIDevice (Hardware)

- (DeviceArchitecture)cpuArchitecture;

@end

// UIDevice+Hardware.m
#import "UIDevice+Hardware.h"

@implementation UIDevice (Hardware)

- (DeviceArchitecture)cpuArchitecture {
    if (sizeof(int *) == 4) {
        return DeviceArhictecture32Bit;
    } else if (sizeof(int *) == 8) {
        return DeviceArchitecture64Bit;
    }
    return DeviceArchitectureUnknown;
}

@end
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4