Objective-C 中常见的数据类型

基本数据类型

  1. BOOL :表示逻辑类型,取值为 YESNO

    复制代码
    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);
相关推荐
蒙小萌19933 小时前
Performance and metrics
ios
shughui4 小时前
APP、Web、H5、iOS与Android的区别及关系
android·前端·ios
Edward.W6 小时前
iOS 17+真机命令行操作对照表
macos·ios·cocoa
2501_916008891 天前
iOS开发APP上架全流程解析:从开发到App Store的完整指南
android·ios·小程序·https·uni-app·iphone·webview
2501_915909062 天前
Charles 抓不到包怎么办?iOS 调试过程中如何判断请求路径
android·ios·小程序·https·uni-app·iphone·webview
2501_916007472 天前
iOS和iPadOS文件管理系统全面解析与使用指南
android·ios·小程序·https·uni-app·iphone·webview
2501_915921432 天前
iOS App 开发阶段性能优化,观察 CPU、内存和日志变化
android·ios·性能优化·小程序·uni-app·iphone·webview
游戏开发爱好者82 天前
在 iOS 开发、测试与上架过程中 如何做证书管理
android·ios·小程序·https·uni-app·iphone·webview
ii_best2 天前
按键精灵安卓/IOS手机助手 × 手机按键 App:1 分钟搞定设备连接(超详细教程)
android·ios·智能手机·自动化·编辑器
2501_916007472 天前
在没有 Mac 的情况下完成 iOS 应用上架 App Store
android·macos·ios·小程序·uni-app·iphone·webview