IOS development-Introduction to OC Data Types

Source: Internet
Author: User

Recommended by blue ou iOS Training Instructors: we hope that more and more people will learn the OC content and learn the iOS development courses. As a senior iOS development engineer required by major enterprises, this is an essential talent for enterprises, so the introduction of "data type" in today's course!

Data types include String, NSDate, NSArry array, and NSDictionary dictionary.

1. String

Strings are often seen at home. In OC, string types are classified into NSString classes, similar to char * in c. You can use the length attribute to obtain the length.

Degrees

1) string Creation Method

650) this. width = 650; "title =" 1) "src =" http://www.bkjia.com/uploads/allimg/131229/1211331344-0.jpg "alt =" 142854597.jpg"/>

2) string Merging Method

650) this. width = 650; "title =" 2) .jpg "src =" http://www.bkjia.com/uploads/allimg/131229/1211333307-1.jpg "width =" 498 "height =" 43 "alt =" 1429079.jpg"/>

3) string truncation method

650) this. width = 650; "style =" width: 499px; height: 48px; "title =" 32.16.jpg "src =" http://www.bkjia.com/uploads/allimg/131229/12113331S-2.jpg "width =" 495 "height =" 45 "alt =" 142928665.jpg"/>

4) string replacement method

650) this. width = 650; "style =" width: 500px; height: 58px; "title =" 42.16.jpg "src =" http://www.bkjia.com/uploads/allimg/131229/1211331526-3.jpg "width =" 500 "height =" 68 "alt =" 143014227.jpg"/>

5) string Comparison Method

650) this. width = 650; "title =" 52.16.jpg "src =" http://img1.51cto.com/attachment/201311/143047937.jpg "width =" 498 "height =" 41 "alt =" 143047937.jpg"/>

2. NSDate

NSDate is a basic class used to process dates and times. It is used to save time values. In addition, it provides some methods to process time difference calculation based on seconds and comparison between dates.

1) class method used to create an NSDate instance

650) this. width = 650; "title =" used to create an nsdate‑class class. jpg "src =" http://www.bkjia.com/uploads/allimg/131229/121133AK-5.jpg "alt =" 143111_6.jpg"/>

3. NSArray unchangeable array for easy search

[Arraycount]: the length of the array.

[ArrayobjectAtIndex0]: input an array script id to obtain the data object.

[ArrayWithObjects;...]: assigns a value to the array object initialization. Here, we can write a pointer to any object, and nil must be used at the end.

NSMutableArray variable object array, delete add and modify.

[NSMutableArrayarrayWithCapacity: 6]: Initialize the length of a variable array object. If the code below continues to add an array that exceeds the length of 6, the length of NSMutableArray will be automatically expanded. 6 is the granularity you can set.

[ArrayaddObject:...]: Add a data object to the end of the variable array.

[ArrayaddObjectsFromArray: ..]: adds an array object to the end of a variable array.

4. Dictionary

The dictionary stores data in the form of Key-Value.

The object storage in the dictionary is unordered and cannot be accessed by subscripts. Each object must be represented by a key.

Dictionary in the cocoa framework: NSDictionary and NSMutableDictionary.

1) create a variable dictionary object

NSMutableDictionary is a subclass of NSDictionary, so it inherits the NSDictionary method.

[NSMutableDictionarydictionaryWithCapacity: 10]: Create a variable dictionary and set its length to 10.

If the length of the dictionary is greater than 10, the length of the dictionary is automatically increased. This method is recommended.

[NSMutableDictionaryinitWithCapacity: 10]: initialize a dictionary with a length of 10.

[DictionarysetObject: @ "Yu Song MOMO" forKey: @ "name"]: dynamically add data to a variable dictionary. The key here is name and the value is Yu Song MOMO. If the dictionary contains data with this KEY, the value of this KEY is directly replaced. Be careful when mixing easily !)

[DictionaryremoveAllObjects ..]: deletes all data in the dictionary.

[DictionaryremoveObjectForKey...]: deletes the data of the specified KEY in the dictionary.

2) create an unchangeable dictionary

[NSDictionarydictionaryWithObjectsAndKeys: ..]: Create a dictionary object using key-value pairs. nil must be used at the end.

The flag ends.

[NSDictionaryinitWithObjectsAndKeys: ..]: uses key-value pairs to initialize dictionary objects. The end must end with the nil flag.

[Dictionarycount]: obtains the length unit of the dictionary.

[DictionarykeyEnumerator]: stores all keys of a dictionary in NSEnumerator. NSEnumerator is similar to an iterator in Java. You can use Quick enumeration to traverse all KEY values in a dictionary.

[DictionaryobjectEnumerator]: stores all dictionary values in NSEnumerator, and its usage is similar to the preceding

The stored Value corresponding to the calendar KEY.

[DictionaryobjectForKey: key]: You can get the stored value of the current KEY by passing in the KEY object.

Although there are a lot of content, there should be no problem in understanding it, and I understand each step very clearly, that is, I hope that everyone can understand it easily and easily, if you have any questions, please feel free to contact us!

Related 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.