Introduced
Object-c is a language that writes programs for Apple iOS and OS X systems. It compiles and builds a common language for command line functionality, GUI, and domain framework. He also offers a number of features to help maintain complex applications.
Like C + +, OBJECT-C also adds object-oriented features to the C language, but the two languages accomplish this goal with a distinctly different base philosophy. Object-c is significantly more inclined to dynamic language, delaying its decision to run, rather than compiling. This performance is developed in iOS and OS x design patterns.
The lengthy naming conventions of objective-c are known to all weeks. The result is that the final code is descriptive, so it is almost impossible to cause misunderstanding or wrong use. For example, code snippets with the same functionality represent the results in C + + and Object-c:
// C++john->drive("Corvette""Mary‘s House")// Objective-C[john driveCar:@"Corvette" toDestination:@"Mary‘s House"]
As you can see, reading in object-c language is more like a natural language, while C + + is more of a machine language. If you're used to Object-c's syntax, it's easy to learn a new project or to learn a third-party code.
Don't worry if you're still not comfortable with the syntax rules for this square bracket. After reading this tutorial you will be familiar with them.
Frameworks
Like other languages, the Object-c language includes a fairly simple grammar rule and a standard development package (SDK).
This tutorial focuses on the language itself. But the tutorial will help you understand some of the frameworks or tools that we can usually use.
There are some standard packages that are not covered in our tutorial, but Apple's Cocoa and Cocoa Touch Framework is currently the most popular. They have defined their respective APIs for OS X app development and iOS app development respectively. The frameworks in Cocoa and Cocoa touch are listed in the table below. For more detailed information, refer to the MAC Technical Overview and iOS Technology Overview.
Framework |
Description |
Foundation |
Defines core object-oriented data types like strings, arrays, dictionaries, etc. We ll explore the essential aspects of this framework in the Data Types module. |
UIKit |
Provides dozens of classes for creating and controlling the user interface on IOS devices. |
AppKit |
Same as UIKit, but for OS X devices. |
CoreData |
Provides a convenient API for managing object relationships, supporting Undo/redo functionality, and interacting with Pers Istent storage. |
MediaPlayer |
Defines a high-level API for playing music, presenting videos, and accessing the user's ITunes library. |
Avfoundation |
Provides lower-level support for playing, recording, and integrating Audio/video into custom applications. |
Quartzcore |
Contains the Sub-frameworks for manipulating images. The Coreanimation framework lets you animate UI components, and Coreimage provides image and video processing capabilities (e.g., filters). |
Coregraphics |
Provides low-level 2D drawing support. Handles path-based Drawing, transformations, image creation, etc. |
Once you're familiar with object-c, there are tools that can help you architect iOS and OS x apps. Again, the tutorial is not a complete tutorial for app development, which means you don't have to learn the framework above. In addition to the foundation framework, you will not learn other frameworks.
If you are interested in Mac app development, you can refer to Ry's Cocoa tutorial, of course, you must first have a solid grasp of object-c. Tutorial teaches you how to build an OS X app using the same method as in this tutorial.
Xcode
Xcode is an integrated development environment (IDE) developed by Apple for the development of Mac, iphone, and ipad applications. It not only error source code Editor, but also includes interface design tool (interface Builder), device simulator, comprehensive testing and debugging tools, The frameworks mentioned in the previous section and the other things you need to develop your app.
Of course there are other ways to compile the Object-c code, but Xcode is certainly the easiest to learn. I recommend that you install Xcode now so that you can follow the examples later in this tutorial. Xcode is available for free from the Mac App Store.
Creating An application Create an app
Xcode provides us with a variety of templates for IOS and OS X apps. All more can be navigated by: File > New > Project ... or cmd+shift+n shortcut key to find. We will open a dialog box asking you to select a template.
For this tutorial, we will select the command line tool template, which can be found through OS X > Application, which is highlighted in. This frees us from the special content of setting Ios/os X, but instead focuses on the object-c itself. Then go down and create a command line tool project. This opens another dialog box that asks you to configure the project information.
You can fill out any of your favorite product name and organization name, and for company identifier use edu.self, this is a standard personal indication. For online apps, if you sign up as an Apple developer, you'll be able to get company marks from Apple.
This tutorial will use some classes that are defined in the foundation framework. So you need to determine the Type field, select Is Foundation. Finally, the use Automatic Reference counting check box is usually selected.
Click Next to prompt you to choose a location for the project store, so you should have a Xcode project that you can use. On the left side of Xcode, you should be able to see a main.m file. Now, this file includes all of your works. Note that files with a. m extension are usually used as source code files for object-c.
To compile the project, you can click the Run button in the top left corner or use the Cmd+r shortcut key. This is what you should be able to see in the output panel of Xcode: Hello, world!
The main () Function
#import <Foundation/Foundation.h>int main(intconstchar * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); } return0;}
In @autoreleasepool block you can write code, experiment with the code snippet of this tutorial. The above main () invokes the function defined in the foundation framework. This is the object-c generic tool, in order to output messages to the console. You also notice that the string in object-c has an @ prefix before it.
Throughout the tutorial, you will observe how the language features work by editing the content in the main.m you see above, but in real development it is almost impossible to modify the contents of the main function provided by the template. For most applications, main () has only one function, which is to give control over to "application delegate". For example, the default main function of the Mac app project is as follows:
#import <Cocoa/Cocoa.h>int main(intconstchar * argv[]) { return NSApplicationMain(argc, argv);}
However, we will always use the command line tools type Project, so the above example is beyond the scope of the tutorial. However, application delegates is part of OS X and IOS apps. The first few chapters of the Ry ' s Cocoa Tutorial will be described in detail.
Get ready!
The next two chapters will learn the C language syntax. Later, we will learn about classes, methods, protocols, and other object-oriented content. This tutorial is made up of a large number of examples that can be practiced. We recommend that you paste the code for these examples and provide some parameters to see what happens in the project you just created.
OBJECT-C Introduction