June 16, 2015
Personal Summary:
Note: Dictionaries and arrays are ID types, and if there are values, note the type conversions;
Dictionaries and arrays are defined and assigned in many similar places and can be remembered together;
Array
Definition Nsarray *array = [[Nsarray alloc] init];
Definition Nsarray *array = [Nsarray array];
Define and assign a value nsarray *array = [Nsarray arraywithobject:@ ""];
Define and assign multiple values
Nsarray *array = [Nsarray arraywithobjects:@ "", @ "", nil];
A new method that can either assign multiple values or assign a value
Nsarray *array = @[@ "", @ ""];
Dictionary
Note: Keys and values appear in pairs
Definition nsdictionary *dictionary = [[Nsdictionary alloc] init];
Definition nsdictionary *dictionary1 = [Nsdictionary dictionary];
Define and assign a key and value nsdictionary *dictionary2 = [nsdictionary dictionarywithobject:@ "value" forkey:@ "key"];
Define and assign multiple keys and values nsdictionary *dictionary3 = [nsdictionary dictionarywithobjectsandkeys:@ "Object", @ "key", @ "Object1", @ "Key1 @ "Object2", @ "Key2", nil];
New method: Nsdictionary *dic1 =
@{@ "Key1": @ "Object1", @ "Key2": @ "Object2", @ "Key3": @ "Object3", @ "Key4": @ "Object4"};
The difference between the values
Array value is the array name and array subscript, such as: array[0], but can not cross, that is, cannot exceed the array.count;array.count array length;
The dictionary value is the function Objectforkey: @ "key";
can also use dictionary[@ "key"];
Another difference is that the dictionary is {value when printing output, value 1; value 2; value 3}, array is (value, value 1, value 2, value 3) or [value, value 1, value 2, value 3]
Variable groups and mutable dictionaries
The variable group cannot use the new method; Nsmutablearray *array = @[@ "", "@" ";
The rest are the same.
Owned method: [Array removeobjectatindex:+]; Remove array subscript to 70 elements
[Array removeobject:@ " skill 7"];// Remove "skill 7 " in array
[Group firstobject];// Gets the first element of the array
[Group lastobject];// gets the last element of the array
[Group Replaceobjectatindex:3 withobject:@ "fengshenghai666"];// replace the third element as fengshenghai666
Variable Dictionaries also cannot use the new method nsmutabledictionary *dic1 =
@{@ "Key1": @ "Object1", @ "Key2": @ "Object2", @ "Key3": @ "Object3", @ "Key4": @ "Object4"};
Two functions
[Dictionary setobject:@ "iphone" forkey:@ "phone"]; Replace or add
[Dictionary removeobjectforkey:@ "Phone"]; Remove key value phone corresponding content
Call notes between an array and a dictionary