IOS Study Notes (1)

Source: Internet
Author: User

From today on, I will release notes during my IOS learning period to help beginners learn how to develop IOS programming faster, you can also have your own reading notes later. Some places may not be detailed, but as long as you follow the learning step by step and do not understand the information, you will be able to learn well. How to declare variable naming rules in Objective-C do not have special character data types. NSInteger can indicate negative integer variables. NSUInteger cannot represent negative Float floating point data, for example, for data of the 1.23 NString type, for example, "Mrs Thomson" NSArray is actually an array. For example, if you have ten file objects, you can store them in it. NSSet you can save Unique, non-repeated collection objects. It is best to use isEqual: NSObject * object1 = [[NSObject alloc] init]; NSObject * object2 = [[NSObject alloc] init]; if ([object1 isEqual: object2]) {NSLog (@ "Both objects are equal. ");} else {NSLog (@" Objects are not equal. ");} creating a custom class is an abstract entity. In OC, a class usually consists of the following two parts: header file :. h is the suffix of the execution file :. in Objective-C, a program returns void, indicating that it does not return the value of a similar function. But it actually returns a value, which is a non-main function written in C language. There are two types of Methods: instance or class. The instance method starts with-and the class method starts with +. Steps for creating a method: 1. Method Type (instance method or class method) 2. Return type of the selected method, and in parentheses. (Void) No return value, (BOOL) A boolean value, (NSObject *) returns an instance of NSObject, and so on. 3. Select a method name starting with a lowercase letter. 4. If your method does not contain parameters, skip to Step 9. 5 and give the parameters two names. A name is a part of the method name, which is used by external methods, and another name is used as a parameter name in the method. 6. After obtaining a name for the parameter, select the data type for the method and enclose it in brackets. 7. Add a colon (if any) after the first selected name of your parameter, and add brackets. The brackets are the data type of the method and the second name of the parameter. 8. Repeat steps 5 to 7 if there are multiple encroaches. 9. insert an open braces after the method name and parameter. The code in braces is used to implement the function of this method. An object must be allocated and initialized before it can be used. You can use the alloc instance method to allocate an object. This method allocates memory space for objects, instance and method of objects. However, the allocated memory is not defined, so it is allocated and initialized before using the object. Objects inherited from NSObject can be used only after two steps: 1. Allocation 2. initialize the attributes of the added class and use the keyword @ property to define the attributes of the class. Any vertex represents an attribute, which is a method shortcut. NSObject * myObject = [[NSObject alloc] init]; myObject. accessibilityHint = @ "Some string"; accessibilityHint is a property definition method: @ property (non atomic, copy) NSString * accessibilityHint; when defining an attribute, it will tell the compiler that we will write a setter and getter method to this attribute. If a value is set here, the setter method will be executed during the runtime. If the attribute is read, the getter method to be executed. In. m, the @ synthesize keyword enables the compiler to automatically generate the setter and getter methods for attributes. @ Property (nonamotic, strong, readonly) NSString * lastName; read-only attribute. Modify manual reference count to automatic reference count (ARC) Storage attributes: strong, weak, unsafe, unretained. Any object managed by ARC has a storage attribute. Strong: objects declared as Strong will be automatically retained during execution and will be valid before the end of the lifecycle, and will be automatically released after the completion. Just like the retain in the traditional memory management method of OC. Www.2cto. comweak: weak reference. If the variable declares this keyword, it is set to nil when the variable pointer of the object is released. For example, if you have two string attributes: strong reference and weak reference, the weak attribute will be set to nil when the strong attribute is released. Unsafe and unretained indicate that only simple variable assignment is performed, meaning that the retain object will not be retained during variable assignment.

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.