Pai daca nu stii nimic despre programare poate ar trebui sa intelegi inainte conceptele Object Oriented Programming (OOP). Dupa ce ai inteles asta bine iti va fi mult mai usor.
C++ este bine sa il studiezi de inceput, si sa faci programe extrem de simple ca sa te acomodezi cu gandirea din spate, si dupa sa treci la Obj-C.
Objective-C este un superset al C++.. deci daca spui ca c++ este optional si obj-C este necesar e ca si cum ai spune ca nu trebuie sa stii NSObject ca sa faci UIView sper c-ati inteles analogia! )
Objective-C este un superset al C++.. deci daca spui ca c++ este optional si obj-C este necesar e ca si cum ai spune ca nu trebuie sa stii NSObject ca sa faci UIView sper c-ati inteles analogia! )
Objective c este un superset al lui c nu al lui c++
Objective-C is a thin layer on top of C, and moreover is a strict superset of C; it is possible to compile any C program with an Objective-C compiler, and to freely include C code within an Objective-C class.
Objective-C derives its object syntax from Smalltalk. All of the syntax for non-object-oriented operations (including primitive variables, preprocessing, expressions, function declarations, and function calls) are identical to that of C, while the syntax for object-oriented features is an implementation of Smalltalk-style messaging.
The Objective-C model of object-oriented programming is based on message passing to object instances. In Objective-C one does not call a method; one sends a message. This is unlike the Simula-style programming model used by C++. The difference between these two concepts is in how the code referenced by the method or message name is executed. In a Simula-style language, the method name is in most cases bound to a section of code in the target class by the compiler. In Smalltalk and Objective-C, the target of a message is resolved at runtime, with the receiving object itself interpreting the message. A method is identified by a selector or SEL — a NULL-terminated string representing its name — and resolved to a C method pointer implementing it: an IMP. A consequence of this is that the message passing system has no type checking. The object to which the message is directed — the receiver — is not guaranteed to respond to a message, and if it does not, it simply raises an exception.
Sending the message method to the object pointed to by the pointer obj would require the following code in C++:
obj->method(argument);
In Objective-C, this is written as follows:
[obj method: argument];
Both styles of programming have their strengths and weaknesses. Object-oriented programming in the Simula style allows multiple inheritances and faster execution by using compile-time binding whenever possible, but it does not support dynamic binding by default. It also forces all methods to have a corresponding implementation unless they are virtual, meaning the method is a placeholder for methods with the same name to be defined in objects derived from the base object. An implementation is still required for the method to be called in the derived object. Smalltalk-style programming allows messages to go unimplemented, with the method resolved to its implementation at runtime. For example, a message may be sent to a collection of objects, to which only some will be expected to respond, without fear of producing runtime errors. Message passing also does not require that an object be defined at compile time. (See the dynamic typing section below for more advantages of dynamic (late) binding.)
Due to the overhead of interpreting the messages, an initial Objective-C message takes three times as long as a C++ virtual method call. Subsequent calls are IMP cached and are claimed to be 50% faster than the C++ virtual method call. The fairness of that comparison is unclear, however, as it disregards the time needed to decide whether a call is IMP-cached. Moreover, the virtual functions table in C++ can also be thought as a function pointers cache. When a virtual function call is compiled, its index in the v-table (table of virtual functions) is known. That value can then be embedded directly into the machine code of the caller by the compiler. This embedding is the optimal scenario. Only a direct non-virtual call to a function’s address is faster. Consequently, no other indirect mechanism such as the caching mechanism, in Objective-C or otherwise, can be faster.