Demo1.mA basic function definition#import//defines a function named Max that returns a value of type int. The parameter passed in is two int type dataintMaxintXinty) { intZ=x>y?x:y; returnZ//return Results}intMainintargcChar*argv[])
Initialize object allocation memory + (ID) alloc;
The birth of an object is essentially a large enough memory from the operating system to hold all the instance variables of the class and designate it as the location of the instance
Block data typeBlock encapsulates a piece of code that can be executed at any timeA block can be used as a function parameter or as a return value of a function and can have an input parameter or return value itself.Apple's official recommendation
1. What is block?① block syntax, essentially an anonymous function (a function without a name);②block is a data type in OC and is widely used in iOS development.③^ is the unique mark of block;The implementation code of the ④block is included in the {
I. Category: (category)is to add a method on the basis of the original class, only the object that is instantiated by the original class can be used when using it.What is the use of the category in the actual development?Already packaged classes,
1 about __block variable Why can I change the value in block
1 2 3 4 5 6 7 8 9 Ten One A - -
void foo(){ __block int i = 1024;//此时i在栈上 int j = 1;//此时j在栈上 void (^blk)(void); blk = ^{printf("%d, %d\n", i, j);
In the Cocoa Foundation, Nsarray and Nsmutablearray are used for an ordered set of objects, the biggest difference between Nsarray and Nsmutablearray classes is that Nsarray is immutable and Nsmutablearray is mutable. They can only store cocoa
Main.m1 #import2 #import "TestClass.h"3 4 intMainintargcConst Char*argv[]) {5 @autoreleasepool {6NSString *purposeinfo =@"the information obtained is useful not only in debug, but also in selector.";7 [TestClass testdebugkeyword:purposeinfo];8 }9
Explain:The Nsarray class has two restrictions. First, it can only store objective-c objects, not the original C-language underlying data types, such as the random pointers in int, float, enum, struct, and Nsarray. Also, you cannot store nil (0 or
Autorelease Pool Usage Precautions:
Under ARC, you cannot use [[NSAutoreleasePool alloc] init], but you should use @autoreleasepool;
Do not put a large number of cyclic operations between the same nsautoreleasepool, which will cause memory
Naming conventions:For the naming of access methods, cocoa has its own conventions. When writing access methods for your own classes, you should follow these conventions so that you and others can read the code without being confused.The setter
One, the visibility of instance variables (access rights)Second, the methodThere are two types of methods in OC: Class, method and instance? method.Class? Method: Can only be used for class, for example: + (ID) Alloc Note: Class? Method cannot be
SuperIn Objective-c, if we need to invoke a method of the parent class in a method of a class, we usually use Super, as follows:@interface Myviewcontroller:uiviewcontroller @end @implementation Myviewcontroller-(void) viewdidload { [super
Atomic: A primitive operation that guarantees the setter/getter of these two methods. If more than one thread calls the setter at the same time, one thread does not appear before the all-setter statement, and the other thread starts to perform the
Main.m1 #import2 /**3 * Test the difference between the pointer type parameter and the common parameter4 *5 * @param A pointer-type parameter6 * @param b general Parameters7 *8 * @return (pointer type parameter +2) + (normal parameter +2)9 */Ten
Introduction to Associations in OBJECTIVE-CReprint please indicate the source of CSDN blog:http://blog.csdn.net/daiyibo123/article/details/46471993How to set associationsWe can use the following methods to correlate properties:objectconstvoidvalue,
Minimize the introduction of additional header files in the header file of the classUse "forward declaration" to introduce header files when there is a need, reducing the number of header files that the class's users need to introduce, and reducing
Brief introductionBased on the C language, you can build a class that requires two files by writing a single-C + + code: . h's header file . m implementation file (if it is a mixed-C + + file with a. mm file suffix) Since there is a header file, so
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.