Objective-C 数组、可变数组
2015-11-27 19:06
363 查看
数组的使用方式
下面是数组:类型NSArray
可变数组 NSMutableArray
下面是数组:类型NSArray
#import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char * argv[]) { // 通过@符号创建数组 NSArray *arr = @[@"Hello",@"jinpangpang"]; // 通过工厂方法创建数组 NSArray *arr2 = [NSArray arrayWithObjects:@"Hello",@"jinpangpang", nil]; // 通过配置文件读取数组 NSArray *arr3 = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]]; for (int i = 0; i<[arr count]; i++) { NSLog(@"%@",[arr objectAtIndex:i]); } @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
可变数组 NSMutableArray
NSMutableArray *arr = [[NSMutableArray alloc] init]; // 开辟一个可变数组对象 for (int i=0;i<100; i++) { [arr addObject:[NSString stringWithFormat:@"值:%d",i]]; // 添加值 } for (int i = 0 ; i<[arr count]; i++) { // 遍历输出 NSLog(@"%@",[arr objectAtIndex:i]); }
相关文章推荐
- Objective-C新特性
- 转: [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- 根据list<Object>中的某个字段排序
- jQuery.each(object, [callback])方法,用于处理json数组
- Objective—C实现UICollectionView中UICollectionViewCell的重排实现
- a different object with the same identifier value was already associated withthe session异常解决方案
- org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案
- org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案
- a different object with the same identifier value was already associated withthe session异常解决方案
- 转:Objective-C与JavaScript的交互
- Javascript] Object,(Date)
- 【原】objc_setAssociatedObject和objc_getAssociatedObject
- sumline text 正则匹配
- Object
- IOS开发基础Object-C(10)—OC内存管理(4)-autorelease使用
- Objective-C RunTime机制(1)
- 在ObjectARX中添加“块”
- 用递归方式解析JSONObject 为HashMap
- Objective C 链式调用
- objective-c 关键字和概念