OBJECTIVE-C Study Notes

Source: Internet
Author: User

    1. OC is an extension of the C language, and almost all applications on OS X or iOS platforms are developed in that language.

    2. You can use the Toolkit cocoa (OS X System) and Cocoa Touch (for iOS systems) to develop fully functional objective-c projects.

    3. Xcode is the development environment that Apple offers to create iOS and OS X applications

    4. Click the Welcome to Xcode option under the Window menu or use the Command+shift+l shortcut key to see the most recently edited item

    5. File->new->new Project, select Mac OS x->application, choose Command Line tool on the right, and finally select the shell type as foundation. Create a project.

    6. Click the Run button or the shortcut key command+r to build and run the program. Using the View->debug area->activate Console or the shortcut command+shift+c, open the Xcode console window to display the output results.

    7. MAIN.M is the source file that contains the OC program code.

#import <foundation/foundation.h>int Main (int argc, const char* argv[]) {NSLog (@ "HELLO objectibe-c!"); return (0);

}//main


8.. m represents a major feature of the MESSAGE,OC.

9. Import into the Foundation.h header file in Framework Foundation

10. A frame is a collection of head files, libraries, pictures, sounds, and so on that is gathered in a separate unit.

Cocoa, Carbon, QuickTime, and OpenGL as a frameset, Cocoa components include: Foundation, Application Kit (AppKit) framework, support framework core animation and core Image.

12. Each frame has a master header file that contains all the header files in the frame. By using #import in the main header file, you can access all the features within the framework.

Xcode uses precompiled header files to speed up reading, and when you import such files through #import, the loading speed is very fast.

14./system/library/frameworks/foundation.framework/headers/contains the header file for the Foundation framework

NSString strings, but strings are generally used with string pointers nsstring. NSLog output, the first parameter must have a @

A. BOOL occupies 8 bits, with Yes and no two values. 8-digit *******0 indicates bool is 0, 8-digit *******1 corresponds to BOOL 1

. OOP (object-oriented Programming) object-oriented programming

18. Indirect (indirection), let other people do something for themselves, or let others replace themselves to complete the work

19. Input of command line parameters (startup parameters), if using Xcode editing program, run, Product->edit scheme,arguments, click the Plus button under Arguments Passed on launch heading, Then enter the startup parameters, OK.

20. In OC, square brackets [] are used to inform an object what to do. The first item in square brackets is the object, and the rest is the action that needs to be performed by the object.

21. In OC, a notification object performs an operation called a send message (also called a "call method"), and [shape draw] indicates that a draw message is sent to the Shape object.

ID shape = Shapes[i];

[Shape draw];


22. Class is a struct that represents an object type

23. An object is a struct that contains a value and a hidden pointer to its class

24. Instance (instance) is another salutation to "object"

25. Messages (message) are actions that an object can perform

26. Method is code that runs in response to a message

27. Method Dispatcher is a mechanism used by OC

28. Interface (interface) is an attribute description provided by the class for an object

29. Implementation (Implementation) is the code that enables the interface to work properly

interface, which is the class in C + +

Implementation, that is, the implementation of class methods in C + +

@interface Circle:nsobject

{

@private

Shapecolor FillColor;

Shaperect bounds;

}

-(void) Setfillcolor: (Shapecolor) FillColor;

-(void) SetBounds: (shaperect) bounds;

-(void) draw;

@end//circle

Note: A class circle is declared, and the parent class is NSObject, which has data members fillcolor and bounds, member methods Setfillcolor, SetBounds, Draw, The return value of Setfillcolor is void and has a parameter fillcolor of type Shapecolor, @end indicates end of class Circle declaration


The @interface is used to define the public interface of the class. Typically, an interface is called an API (Application programming Interface)

31. Implementation of Classes

@implementation Circle

-(void) Setfillcolor: (Shapecolor) C

{

FillColor = C;

}//setfillcolor

-(void) SetBounds: (shaperect) b

{

bounds = b;

}//setbounds

Note: @implementation is a compiler directive that indicates that you will provide code for a class. The next step is the definition of each method. You can define methods that are not present in the declaration and can be seen as private methods that can only be used in the current class implementation. However, there is no real private method in OC, nor is it possible for a method to be identified as a private method, which prevents other code from calling it. The side effects of this OC dynamic nature.


The. OC Runtime is a code block that supports these applications when the user runs the application.

33. The process of creating an object, called instantiation (instantiation)

34. When instantiating an object, it is necessary to allocate memory and then initialize and save the memory as a useful default value that differs from the random value obtained through the newly allocated memory. After the memory allocation and initialization work is complete, it means that the new object instance has been created.

A feature of OC that can send a message to a class as an object.

36. In order to create a new object, send the new message to the appropriate class. After the class receives and processes the new message, we get a fresh object instance that we can use.

int main (int argc, const char* argv[])

{

ID Shape[3];

Shaperect rect0 = {0, 0, 10, 30};

Shapes[0] = [Circle new];

[Shapes[0] setbounds:rect0];

[Shapes[0] setfillcolor:kredcolor];

...

Drawshapes (shapes, 3);

return (0);

}//main


OBJECTIVE-C Study Notes

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.