Saturday, December 21, 2013

--- OC rookie ask why you need to initialize the object?

Test * test = [[Test alloc] init]; initialization / / object and the space allocated for the object

So initialization methods?

Now that the space allocated for the object, why give way to initialize it?

Reply:
Objective-C is the most important feature of object-oriented messaging (message passing) model. Objective-C, the object does not call the method, but pass messages to each other, which is today's mainstream object-oriented C + +-style style varies greatly. The difference between these two styles is how the main program call methods treat / transfer news this action. Relationship in C + + classes and methods are very strict clearly a method must belong to a class, and at compile time (compile time) has been closely tied together, you can not call a class method does not exist. But in Objective-C, class looser relationship with the message, all methods are considered a response to the message, and call the method is considered the class to send a message. All messages processed until runtime (runtime) will be determined dynamically, and by the class to decide how to handle the messages received. In other words, a class does not guarantee that we'll respond to messages received, if the class received a message that can not be processed, the program does not error or crash, it will throw an Exception.
So the first point of the first not to use it as a general object-oriented language
Objective-C by creating objects need two messages: alloc and init. alloc role is distributed memory space, init is to initialize an object. init and alloc are defined in the NSObject class method, when the object receives both the message and make the correct response, the new entity is considered ready
Reply:
On the top floor
Reply:
Learning the ~
Reply:
Learning, and are interested, join qq group it together to improve professional development group 4633616 iphone
Reply:
alloc is allocated space, init is the object initialization.
Reply:
Early use of the new, two steps later, alloc and init, as is adaptation initwithXXX.

Reply:
Learn the

Reply:
6th Floor, a floor that is allocated space for alloc init initializes OC There is also easy initialization as initwithFormat: other methods
Reply:
Proposed landlord's look at some basic tutorials OC and C C + + is very similar looking to make IPHONE development point of entry, then read the book will be able to do a few simple examples easy to use
Reply:
Today began the next review, summarized under the bar
For example:
Car * myCar = [Car alloc] init];
alloc: in accordance with the Car class (template) to allocate memory to myCar this object.
init: create an instance (object) in accordance with the Car class (template) out.

No comments:

Post a Comment