OC Note 1: Objective-C introduction, oc note objective-c
1. OC Introduction
Objective-C is an object-oriented programming language that expands C and is mainly used for iOS and Mac OS development.
- Based on the C language, a minimum object-oriented syntax is added.
- Fully compatible with C language
- The C language code or even C ++ code can be incorporated into the OC code.
- You can use OC to develop Mac OS X and iOS applications.
2. OC syntax Overview
2.1 keywords
Each language has keywords, such as the flaot and int of C language. What are the keywords of oc?
Basically, all keywords start @.
The following lists some common keywords. You can preview them first, so you don't need to review the information to find their meanings.
@interface、@implementation、@end @public、@protected、@private、@selector @try、@catch、@throw、@finally @protocol、@optional、@required、@class@property、@synthesize、@dynamicself、super、id、_cmd、__block、__strong、__weak
2.2 The string starts @
For example, @ "Hello" is a string in OC, while "Hello" is a string in C.
2.3 other syntax
2.4 differences between NSLog and printf
- NSLog receives OC strings as parameters, and printf receives C language strings as parameters.
- NSLog output will automatically wrap, and printf output will not automatically wrap the setMethod andGetMethod
- To use NSLog, # import <Foundation/Foundation. h>
- To use printf, # include <stdio. h>
2.5Role of the Foundation framework
Development of essential frameworks for OC, iOS, and Mac programs
- This framework contains many common APIs (application programming interfaces)
- The Framework contains many header files. If you want to use the content of the entire framework, you can include the main header file.
# Import <Foundation/Foundation. h>
3. Differences between OC and other languages
3.1 similarities and differences between Objective-C and C:
1. As a structured language, C has a clear hierarchy, which makes it easy to organize programs in a modular manner, debugging and maintenance. Objecive-C extends the C language to provide object-oriented design capabilities, for example, class and messages' inheritance. At the same time, the Objective-C code can contain C and C ++ statements, which can call C functions, you can also use the C ++ object access method;
2. Strong C Performance and processing capabilities. You can directly access the physical address of the memory for bit-level operations. The C language implements hardware programming, therefore, the C language integrates the functions of advanced and low-level languages, which can be used for system software development and application software development. Objective-C can implement underlying system programming, on the other hand, dynamic architecture can be used for development.
3.2Differences between Objective-C and C ++:
1. Single inheritance:
Like Java and Smalltalk, Objective-C does not support multiple inheritance, while C ++ supports multiple inheritance.
2. Dynamic:
Objective-C is dynamicaly typed, and its class library is easier to operate than C ++. Objective-C allows access to methods and classes based on string names at runtime, and supports dynamic connection and addition of classes.
4. OC Learning Method
After mastering the C language, it is easier to learn OC. Since OC is an object-oriented language and C is a process-oriented language, you need to have some object-oriented knowledge after learning C. As long as you follow the proper and gradual learning methods, you can learn well. OC learning can be roughly divided into these aspects:
1. Object-Oriented Programming
2. Classes and objects
3. Create classes and objects
4. set and get Methods
5. Class and object Methods
6. keywords such as self
7. Inheritance and Polymorphism
8. simple use of strings
9. Category
10. Memory Management
11. Protocol proxy
12. Block
13. Singleton
14. ARC
15. Use of strings
16. Foundation framework