All actions for iOS immutable groups

Source: Internet
Author: User

#pragma mark to create an array

1. Creating an array from an object method

Nsarray * array = [[Nsarray alloc]initwithobjects:@ "one", @ "one", @ "three", @ "four", @ "Five", nil];

NSLog (@ "%@", array);

Nil means null, the essence is 0, if the underlying data type pointer with a null table, the object points to null generally with nil to indicate that the class object is null with nil;

Class--> class type

SEL--Selector

Creating an array from a class method

Nsarray * array1 = [Nsarray arraywithobjects:@ "1", @ "2", @ "3", @ "4", @ "5", nil];

The number of days from Xcode4.6 allows objects to be created in the following ways

NSNumber @ () quick Convert basic array type to NSNumber object

Some companies are not allowed to use arrays created with object methods or class methods for consistent recommendation

Dog * dog = [[Dog alloc]init];

Nsarray * Array3 = @[@ "One", @ "one", @ "three", @ "four", @ "Five", dog];

id--> complete pointer-to receive objects of any data type

The array itself is an object

Array elements such as @ "one", @ "one", @ "three", @ "four", @ "Five" and so on are any type objects, not limited to string

Creates an array object Shishun, passing in the address of the object

An array can store only the address of the redemption, not the object's ontology.

The same object can be stored in two arrays, still the same object.

The object is modified in one array, and the object is read in another array, and it is also modified.

Arrays can be stored in arrays

In fact%@ can print any object, as long as the object rewrite description put

NSLog (@ "%@", array3);

#pragma the number of members of the Mark array

Nsuinteger num = [array count];

NSLog (@ "%lu", num);

#pragma a member of the Mark array

0~n-1

Error message: Index 5 beyond bounds [0:4] ' array out of bounds

NSString * str = [array objectatindex:3];

NSLog (@ "%@", str);

Xcode4.6 Array Members

NSLog (@ "%@", array[2]);

#pragma mark gets the position of an array element in the array

Nsuinteger index = [array1 indexofobject:@ "1"];

NSLog (@ "%lu", index);

#pragma mark determines if an array contains an element

BOOL tag = [array containsobject:@ "Five"];

NSLog (@ "%d", tag);

#pragma mark gets the first element/last element

NSString * str2 =[array1 firstobject];

NSString * STR3 = [array1 lastobject];

NSLog (@ "%@%@", str2, STR3);

#pragma mark to stitch the elements of an array

Operations on String objects only

NSString * STR4 = [array componentsjoinedbystring:@ ""];

NSLog (@ "%@", STR4);

#pragma mark to split the string

NSString * STR5 = @ "yes,i am a So bad man";

Splitting a string

Nsarray * Array4 = [STR5 componentsseparatedbystring:@ "];

NSLog (@ "%@", Array4);

Splits the string, generates a bunch of new substrings, and the original string is unchanged, and the method creates an array that adds each substring to the current array.

Nscharacterset * set = [Nscharacterset charactersetwithcharactersinstring:@ ","];

Nsarray * Array5 = [STR5 componentsseparatedbycharactersinset:[nscharacterset charactersetwithcharactersinstring:@ ", "]];

Set is a collection

[Nscharacterset charactersetwithcharactersinstring:@ ","] This method creates a collection of objects, returns the object address, character set in character, the @ "from the string,"

NSLog (@ "%@", array5);

#pragma the mix of the mark array elements

Dog * Dog1 = [[Dog alloc]init];

Cat * CAT1 = [[Cat alloc]init];

Dog * dog2 = [[Dog alloc]init];

Cat * Cat2 = [[Cat alloc]init];

Dog * Dog3 = [[Dog alloc]init];

Nsarray * Array6 = @[dog1,cat1,dog2,dog3,cat2];

Judging that an object belongs to a class

-(BOOL) Iskindofclass: (Class) class;

for (id obj in array6) {

if ([obj Iskindofclass:[dog class]]) {

NSLog (@ "B elder brother");

}

if ([obj Iskindofclass:[cat class]]) {

NSLog (@ "Dragons");

}

}

All actions for iOS immutable groups

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.