zoukankan      html  css  js  c++  java
  • [转]Objectc数组

    在object-c中,C语言的数组格式初始化和引用都能够用,但在object-c中不提倡使用。

    (1)不可变数组:NSArray

    初始化: 

    NSArray*array=[[NSArray alloc] init];

    相同的初始化方法还有:

    initWithArray;

    initWithContentsOfFile;

    initWithContentsOfURL;

    initWithObjects;

    同样还可以通过如下方法创建一个数组:

    arrayWithArray;

    arrayWithContentsOfFile;

    arrayWithContentsOfURL;

    arrayWithObject;

    arrayWithObjects;

    其他详细的可以参考IOS开发者文档。

    (2)可变数组:NSMutableArray

    NSMutableArray是在开发中最常用的数组,常用如下声明:

    初始化:

    NSMutableArray *mutableArray =[[NSMutableArray alloc] init];

    还有:

    arrayWithArray;

    arrayWithArray:array;

    arrayWithObjects:;

    arrayWithCapacity;

    initWithCapacity;

    另外还有增加元素的删除元素的方法,如下:

    addObject:

    addObjectFromArray:

    insertObject:atIndex:

    removeObject:

    removeObjectAtIndex:

    具体的可以参照IOS开发文档

    (3)字典:NSDictionary

     初始化的方法有:

    NSDictionary *dictionary = [NSDictionary alloc] initWithObjectsAndKeys:
    @"number1",@"1",@"number2",@"2",@"number3",@"3",nil];
    同样也有多种相似的初始化方法,但开发中最常用的是:

      + (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys

     

      这个可以根据键值对对相同的键值进行配对,对存储成对的数据非常管用。

      相同的字典也有可变字典:NSMutableArrayDictionary.这个属性的具体情况类似NSMutableArray,

    具体可以查看IOS开发文档

    原文地址:http://blog.csdn.net/leikezhu1981/article/details/6904125

  • 相关阅读:
    android manifest.xml 文件
    android 打开 res raw目录 中 数据库文件
    android intentService
    android 注册广播接受者
    android activity 窗口 样式
    android activity 生命周期
    android 后台 activity 被系统回收 保存状态
    Python的包管理工具easy_install, setuptools, pip,distribute介绍
    Python的包管理工具easy_install, setuptools, pip,distribute介绍
    MySQL 1071错误解决办法
  • 原文地址:https://www.cnblogs.com/greywolf/p/2781894.html
Copyright © 2011-2022 走看看