In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you the basic knowledge about Objective-C. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
OC is an extension set of the C language, and almost all applications on OS X or IOS platforms are developed in that language.
You can use toolkits Cocoa (for OS X systems) and Cocoa Touch (for IOS systems) to develop fully functional Objective-C projects.
Xcode is the development environment provided by Apple to create IOS and OS X applications.
Click the Welcome to Xcode option under the window menu or use the Command+Shift+l shortcut to see the most recently edited project
File- > New- > New Project, select Mac OS X-> Application, select Command Line Tool on the right, and finally select Foundation as the command line tool type. Create a project.
Click the Run button or the shortcut key Command+R to generate and run the program. Use View- > Debug Area- > Activate Console or the shortcut key Command+Shift+C to open the Xcode console window and display the output.
Main.m is the source file that contains the OC program code.
# import int main (int argc, const char* argv []) {NSLog (@ "HELLO Objectibe-C!"); return (0)
} / / main
8. M represents one of the main features of message,OC.
9. Import introduces the Foundation.h header file in the framework Foundation
10. A frame is a collection of header files, libraries, pictures, sounds, etc., gathered in a separate unit.
11. Cocoa, Carbon, QuickTime and OpenGL are used as framesets. The components of Cocoa are: Foundation, Application Kit (AppKit) framework, supporting framework Core Animation and Core Image.
twelve。 Each frame has a main header file, which contains all the header files within the framework. By using # import in the main header file, you can access all the functions within the framework.
13. Xcode uses precompiled header files to speed up reads, which can be loaded very quickly when imported through # import.
14./System/Library/Frameworks/Foundation.framework/Headers/ contains the header file of the Foundation framework
15. NSString strings, but strings generally use string pointers NSString. When NSLog is output, the first parameter must have @
16. BOOL occupies 8 bits, with two values of YES and NO. 8-digit * 0 means 0 for BOOL, and 1 for 8-digit * 1 corresponding to BOOL
17. OOP (Object-Oriented Programming) object-oriented programming
18. Indirection, let someone else do something for you, or let someone else do the work for you.
19. Input the command line parameters (startup parameters). If you use the Xcode editor, run time, Product- > Edit Scheme,Arguments, click the plus button under the heading of Arguments Passed On Launch, and then enter the startup parameters, OK.
20. In OC, square brackets [] are used to tell an object what to do. The first item in square brackets is the object, and the rest are the operations that need the object to perform.
21. In OC, telling an object to do something is called sending a message (also known as "calling a method"), and [shape draw] means sending a draw message to a shape object.
Id shape = shapes [I]
[shape draw]
twenty-two。 A class is a structure that represents the type of an object
23. An object is a structure that contains values and hidden pointers to its class
24. Instance is another name for "object"
25. A message is an operation that an object can perform
twenty-six。 A method (method) is code that runs in response to a message
twenty-seven。 Method scheduling (method dispatcher) is a mechanism used by OC
twenty-eight。 Interface (interface) is the property description provided by a class to an object
twenty-nine。 Implementation (implementation) is the code that makes the interface work properly
/ / API, 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, the parent class is NSObject, it has data members fillColor and bounds, the member methods setFillColor, setBounds, draw, the return value of setFillColor is void and a parameter of type ShapeColor fillColor,@end indicates the end of the class Circle declaration
thirty。 @ interface is used to define the public interface of the class. In general, the interface is called API (Application programming interface)
thirty-one。 Implementation of the class
@ 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. Next is the definition of each method. You can define methods that do not appear in the declaration and think of them as private methods that can only be used in the current class implementation. However, there are no truly private methods in OC, and there is no way to identify a method as private, thus preventing other code from calling it. The side effects of this dynamic nature of OC.
thirty-two。 The OC runtime is a block of code that supports applications when users run them.
thirty-three。 The process of creating an object is called instantiation
thirty-four。 When you instantiate an object, you need to allocate memory, and then initialize and save that memory as useful default values, which are different from the random values obtained from the newly allocated memory. After the memory allocation and initialization work is complete, it means that the new object instance has been created.
thirty-five。 A feature of OC that allows you to send messages to classes as objects.
thirty-six。 To create a new object, you need to send a new message to the corresponding class. After the class receives and processes the new message, we get a new object instance that can be used.
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
Object-oriented guru Bertrand Meyer's Open / close principle (Open/Closed Principle), that is, software entities should be open to extensions and closed to modifications.
These are the basic knowledge of Objective-C shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.