IOS Development OC Foundation article

Source: Internet
Author: User

In iOS development, if you can understand the characteristics of OC objects, reasonable use of the appropriate objects, will greatly simplify the complexity of the code and the amount of code.

OC object is a class, the most commonly used is nsarray,nsmutablearray,nstring,nsutablestring,nsdictionary,nsmutabledictionary. Depending on the class name, you can tell what type the class is. Below to give you a brief introduction of these OC objects, but not too deep to explain the use of the object, you can see the API will be more effective.

The first is nstring,nsutablestring. They are all string objects. The difference is that the former is immutable and the latter is mutable. NSString does not indicate that the value of the variable declared by this object is immutable, but rather that after it is initialized, you cannot change the memory value allocated by the variable, but you can reassign the memory space in which the variable is located. As an example:

NSString * str = @ "Lee is a loner.";

STR initialization succeeds, you can not change @ "Lee is a loner." But you can do the following:

str = @ "Lee is going die alone."

That's right.

NSString is very powerful, and its processing of strings is much simpler than the C language. Because it is a class, Apple has encapsulated a lot of practical methods, such as: Add a string to the end of another string, count the number of strings, determine whether two strings are equal, intercept the specified string, and so on.

Nsutablestring is a mutable string, which means that you can append its memory space, or modify the value in the memory space it allocates. It is a subclass of NSString, so the method of NSString it also has. It is more than nsstring and other functions, such as adding and removing changes, the specific method of implementation please consult the API.

Then say Nsarray,nsmutablearray, they are array objects, the literal difference is the same, but the OC array can only access the object, so the basic data type is not stored in the array, you want to save the basic data type can be converted to NSNumber or nsstring. The array object also cannot save nil, because nil is used as the end flag in the array. Use the method to find the API yourself.

Finally say nsdictionary,nsmutabledictionary, they are Dictionary object, literal difference ibid. A dictionary is a collection of key-value, which is unordered, meaning that the order of all the output of a dictionary may not be the same, and of course there is no way to index the dictionary or anything. A dictionary is a multiple-to-one collection, and only one value can exist. In addition, dictionaries and arrays can only access objects. There are some ways to find the API for the dictionary yourself.

IOS Development OC Foundation article

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.