Objective-C 中常见的数据类型

基本数据类型

  1. BOOL :表示逻辑类型,取值为 YES 或 NO。

    复制代码
    BOOL isTrue = YES;
  2. char:表示单个字符。

    复制代码
    char grade = 'A';
  3. int:表示整数。

    复制代码
    int score = 90;
  4. float:表示单精度浮点数。

    复制代码
    float height = 1.75;
  5. double:表示双精度浮点数。

    复制代码
    double pi = 3.14159;

复合数据类型

  1. NSArray:表示不可变数组,包含一组有序的对象。

    复制代码
    NSArray *numbers = @[@1, @2, @3];
  2. NSMutableArray:表示可变数组,可以动态添加、删除元素。

    复制代码
    NSMutableArray *mutableArray = [NSMutableArray arrayWithObjects:@"Apple", @"Banana", @"Orange", nil];
  3. NSString:表示不可变字符串。

    复制代码
    NSString *name = @"John";
  4. NSMutableString:表示可变字符串,可以动态修改字符串内容。

    复制代码
    NSMutableString *mutableString = [NSMutableString stringWithString:@"Hello"];
  5. NSDictionary:表示不可变字典,包含一组键值对。

    复制代码
    NSDictionary *person = @{@"name": @"John", @"age": @30};
  6. NSMutableDictionary:表示可变字典,可以动态修改字典内容。

    复制代码
    NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary]; [mutableDictionary setObject:@"Apple" forKey:@"fruit"];

指针类型

  1. id:通用对象指针类型,可以指向任何 Objective-C 对象。

    复制代码
    id object = @"Hello";
  2. Class:表示类对象指针类型,用于表示类的类型。

    复制代码
    Class classObject = [NSString class];
  3. SEL:表示方法选择器类型,用于表示方法的名称。

    复制代码
    SEL selector = @selector(description);
相关推荐
茶底世界之下11 小时前
方图一定要裁照片吗?用 Awaking 比较裁切与留白
ios
00后程序员张13 小时前
无需 Mac 的 iOS App 上架工具,开心上架Appuploader 负责哪些环节
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063213 小时前
Windows 用 KXBuild 开发 iOS 项目,CocoaPods、SPM 怎么处理?
windows·vscode·ios·个人开发·swift·敏捷流程·cocoapods
2501_9159090614 小时前
KXApp 能打开哪些 iOS 项目?xcodeproj 与 CocoaPods 支持清单
ide·vscode·ios·个人开发·xcode·敏捷流程·cocoapods
开心就好20251 天前
uni-app 本地打包 iOS,在 Windows 上使用 KXBuild 产出 ipa 并上架的完整流程
后端·ios
调试人生的显微镜1 天前
跨平台抓包工具怎么选?TraceEagle抓包鹰 的四种跨平台能力
后端·ios
2501_915909061 天前
Ipa Guard 防护上架,混淆、重签名和回归测试怎么做
android·ios·小程序·https·uni-app·iphone·webview
木头分享1 天前
2026淘宝、京东双11活动全自动脚本丨IOS+安卓
ios
茶底世界之下1 天前
红花太抢眼,蓝天又想留下:用 Awaking 比较两种减饱和
ios
2501_916008891 天前
Windows 上写第一个 SwiftUI App,KXBuild 空工程起步,跑到 iPhone 真机
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程