当前位置: 首页 > wzjs >正文

如何做做网站企业邮箱

如何做做网站,企业邮箱,文化传媒公司能否建设经营网站,餐饮加盟网站模板目录 一、C语言基础快速回顾 1. 基本数据类型 2. 运算符 3. 控制流 4. 数组与结构体 二、Objective-C核心类型详解 1. NSString - 字符串处理 2. NSNumber - 基本类型对象化 3. NSArray - 有序集合 4. NSDictionary - 键值对集合 5. nil与NULL的区别 三、动手实践 …

目录

一、C语言基础快速回顾

1. 基本数据类型

2. 运算符

3. 控制流

4. 数组与结构体

二、Objective-C核心类型详解

1. NSString - 字符串处理

2. NSNumber - 基本类型对象化

3. NSArray - 有序集合

4. NSDictionary - 键值对集合

5. nil与NULL的区别

三、动手实践

1. 字符串操作示例

2. 数组操作示例

3. 字典操作示例

四、总结

相关推荐


一、C语言基础快速回顾

1. 基本数据类型

Objective-C作为C的超集,完全支持C语言的所有基本数据类型:

int age = 25;                   // 整型
float height = 1.75f;           // 单精度浮点
double pi = 3.1415926535;       // 双精度浮点
char initial = 'J';             // 字符型
BOOL isStudent = YES;           // Objective-C特有的布尔类型(YES/NO)

2. 运算符

// 算术运算符
int sum = a + b;
int diff = a - b;
int product = a * b;
float quotient = (float)a / b;// 比较运算符
if (a == b) { /* ... */ }
if (a > b) { /* ... */ }// 逻辑运算符
if (condition1 && condition2) { /* ... */ }
if (condition1 || condition2) { /* ... */ }

3. 控制流

// if-else
if (score >= 90) {grade = 'A';
} else if (score >= 80) {grade = 'B';
} else {grade = 'C';
}// for循环
for (int i = 0; i < 10; i++) {printf("%d\n", i);
}// while循环
while (condition) {// 循环体
}// do-while循环
do {// 至少执行一次
} while (condition);

4. 数组与结构体

// 数组
int numbers[5] = {1, 2, 3, 4, 5};
numbers[0] = 10;// 结构体
struct Person {char name[50];int age;
};
struct Person p1 = {"John", 30};

二、Objective-C核心类型详解

1. NSString - 字符串处理

创建字符串:

NSString *greeting = @"Hello, Objective-C!";
NSString *name = [[NSString alloc] initWithFormat:@"%@ %@", firstName, lastName];

常用方法:

// 获取长度
NSUInteger len = [greeting length];// 子字符串
NSString *sub = [greeting substringFromIndex:7]; // "World!"
NSString *subRange = [greeting substringWithRange:NSMakeRange(0, 5)]; // "Hello"// 比较
if ([str1 isEqualToString:str2]) {// 字符串内容相等
}// 大小写转换
NSString *upper = [greeting uppercaseString];
NSString *lower = [greeting lowercaseString];// 查找
NSRange range = [greeting rangeOfString:@"World"];
if (range.location != NSNotFound) {NSLog(@"Found at index %lu", range.location);
}

2. NSNumber - 基本类型对象化

创建NSNumber:

NSNumber *intNum = @42;
NSNumber *floatNum = @3.14f;
NSNumber *doubleNum = @3.1415926535;
NSNumber *boolNum = @YES;

转换回基本类型:

int i = [intNum intValue];
float f = [floatNum floatValue];
BOOL b = [boolNum boolValue];

3. NSArray - 有序集合

不可变数组(NSArray):

NSArray *colors = @[@"Red", @"Green", @"Blue"];
id firstColor = colors[0];  // 或者 [colors objectAtIndex:0]
NSUInteger count = [colors count];// 遍历
for (NSString *color in colors) {NSLog(@"%@", color);
}// 包含检查
if ([colors containsObject:@"Green"]) {NSLog(@"包含绿色");
}

可变数组(NSMutableArray):

NSMutableArray *mutableColors = [NSMutableArray arrayWithArray:colors];
[mutableColors addObject:@"Yellow"];
[mutableColors insertObject:@"Black" atIndex:0];
[mutableColors removeObject:@"Red"];
[mutableColors removeObjectAtIndex:1];

4. NSDictionary - 键值对集合

不可变字典(NSDictionary):

NSDictionary *person = @{@"name": @"John",@"age": @30,@"isStudent": @NO
};NSString *name = person[@"name"];  // 或者 [person objectForKey:@"name"]

可变字典(NSMutableDictionary):

NSMutableDictionary *mutablePerson = [NSMutableDictionary dictionaryWithDictionary:person];
[mutablePerson setObject:@"Doe" forKey:@"lastName"];
[mutablePerson removeObjectForKey:@"isStudent"];

5. nil与NULL的区别

  • NULL是C语言的空指针
  • nil是Objective-C对象的空指针
  • 现代Objective-C中,两者基本可以互换,但约定俗成:
    • 对象用nil
    • 普通指针用NULL
NSString *str = nil;  // Objective-C对象
int *ptr = NULL;      // C指针

三、动手实践

1. 字符串操作示例

        NSString *firstName = @"SCC";NSString *lastName = @"Shuaici";// 字符串拼接NSString *fullName = [NSString stringWithFormat:@"%@==>%@", firstName, lastName];// 字符串分割NSArray *components = [fullName componentsSeparatedByString:@"==>"];// 字符串替换NSString *modified = [fullName stringByReplacingOccurrencesOfString:@"Shuaici" withString:@"Shuaici-SVIP"];

2. 数组操作示例

// 创建数组
NSArray *originalArray = @[@1, @2, @3, @4, @5];// 映射
NSMutableArray *squaredArray = [NSMutableArray array];
for (NSNumber *num in originalArray) {[squaredArray addObject:@([num intValue] * [num intValue])];
}// 过滤
NSPredicate *evenPredicate = [NSPredicate predicateWithFormat:@"modulus:by:(SELF, 2) == 0"];
NSArray *evenNumbers = [originalArray filteredArrayUsingPredicate:evenPredicate];// 排序
NSArray *sorted = [originalArray sortedArrayUsingSelector:@selector(compare:)];

3. 字典操作示例

// 创建字典
NSMutableDictionary *employee = [NSMutableDictionary dictionary];
[employee setObject:@"Shuaici" forKey:@"name"];
[employee setObject:@30 forKey:@"age"];
[employee setObject:@"Developer" forKey:@"position"];// 更新值
[employee setObject:@31 forKey:@"age"];// 遍历
for (NSString *key in employee) {NSLog(@"%@: %@", key, employee[key]);
}// 字典转JSON
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:employee options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

四、总结

        Objective-C在C语言基础上引入了丰富的面向对象特性,其中核心类型如NSString、NSNumber、NSArray和NSDictionary是日常开发中最常用的类。理解这些类型的特点和用法是掌握Objective-C开发的基础。不可变类型(NSString, NSArray, NSDictionary)和它们的可变版本(NSMutableString, NSMutableArray, NSMutableDictionary)之间的区别尤其重要,这关系到代码的安全性和性能。

相关推荐

C语言基础精讲-CSDN博客文章浏览阅读10w+次,点赞413次,收藏2.1k次。C语言是当代人学习及生活中的必备基础知识,应用十分广泛,下面为大家带来C语言基础知识梳理总结,C语言零基础入门绝对不是天方夜谭!_c语言基础知识 https://shuaici.blog.csdn.net/article/details/60570837

为何要学习Objective-C?从环境搭建开始-CSDN博客文章浏览阅读514次,点赞10次,收藏10次。在Objective-C开发中,你会频繁遇到以"NS"开头的类名和函数名,比如NSLog、NSString、NSArray等。这个"NS"前缀其实有着重要的历史渊源和技术含义。 https://shuaici.blog.csdn.net/article/details/148535298

http://www.dtcms.com/wzjs/19114.html

相关文章:

  • 如何自己做优惠券网站百度有人工客服吗
  • 为网站做一则广告语关键词推广软件排名
  • 微网站设计北京自动seo
  • 深圳龙岗高端网站建设百度搜索高级搜索技巧
  • 做调查网站赚钱百度图片收录提交入口
  • 网站专题页如何做网站关键词优化
  • 藤县建设局网站百度的广告
  • wordpress刷留言seo技术中心
  • 网站宽度 1000px网站推广100种方法
  • 网站程序文件软文写作技巧有哪些
  • 广州 科技网站建设公司网站维护公司
  • 网站一般用什么软件做可以免费发布广告的平台有哪些
  • 刚做的网站搜全名查不到汽车网站建设
  • 怎么做国外网站南昌网站seo外包服务
  • 十堰网站网站建设新浪新闻疫情
  • 西部数码网站管理助手卸载信息流优化师没经验可以做吗
  • 宜春网站建设哪家专业营销一体化平台
  • 石碣镇做网站手机百度如何发布广告
  • 搜狗推广效果好吗深圳排名seo
  • 企业员工餐解决方案站内优化主要从哪些方面进行
  • 做外贸零售和批发批发网站自己怎么做游戏推广赚钱
  • 天河网站建设信科网络自己怎么免费做网站
  • 政府门户网站建设的建议网络广告营销的概念
  • 合肥建设工会网站安徽网站seo
  • 手机型网站室内设计培训哪个机构比较好
  • 动态网页制作网站谁有恶意点击软件
  • 营销网站案例长春seo排名优化
  • 百家号如何给网站做推广百度热搜榜排名昨日
  • 勒流网站建设天津百度关键词推广公司
  • 西宁公司官方网站建设seo搜索优化公司报价