Getting started with iOS development☞OC language · pre-school preparation, iosoc
Basic knowledge 1. Preface
In Windows, the executable file format is. exe.
The Mac system executable file format can be any
The OC language is enhanced and expanded on the basis of the C language. The OC language is compatible with all the C language syntax, and its unique features are generally used by itself.
2. system class prefix
System class prefix NS = NEXTSTEP in Cocoa
3. Keywords
Most keywords start.
4. Running Process
- Write OC source files:. m,. c
- Compile: cc-c xxx. m xxx. c
- Link: cc xxx. o xxx. o-framework Foundation (to use the Foundation framework, add-framework Foundation)
- Run:./a. out
[Note: Compilation and link can be merged: cc xxx. m xxx. m-framework Foundation]
5. # import
# Import is a pre-processing command, which is similar to # include in C language. It contains (copies) the content of a file to the position of the pre-processing command.
- # Purpose of import:
- Like # include, copy the file content.
- This automatically prevents duplicate copies of the object content.
- # Import to include the header file. The advantage is that it can automatically prevent the same header file from being contained multiple times.
# Import <...> indicates that the file that comes with the system is included. # import "..." indicates that the file created by the developer is included.
- # Import <Foundation/Foundation. h>
- Contains the Foundation. h file under the Foundation framework
- Foundation. h is the main header file (the content inside is the link of all header files under the Foundation framework)
- [The Name Of The main header file must be consistent with the framework name]
- You only need to include the primary header file to use the entire framework!
In Xcode:
Press and hold the command key and click to access the details of the framework and method.
Shortcut Keys: command + F
6. Data Type
- Boolean (Boolean, true/false) and BOOL (Boolean, YES/NO) types in OC can be used for logical judgment!
- The role of the SEL type:
Method selector @ selector (method name)
(1) check whether a method is implemented in the object (class) with the object (class)
RespondsToSelector notes:
- If you use an object to call this method, it will determine whether the object has implemented a method starting "-".
- If this method is called through a class, it will determine whether the class has a method starting with "+ ".
(2) Use an object (class) to call a SEL Method
(3) The matching object uses the SEL type as the method parameter, that is, "@ selector (method name)" can be used as a method parameter (passing a method as a parameter of another method)
You can upload the method of one object to the method of another object for execution.
7. for Loop in OC
8. Methods for capturing exceptions in OC
@ Try... @ Catch... @ Finally
9. Modify the project template
- Modify the content of the project template and main function:
/Applications/Xcode. app/Contents/Developer/Library/Xcode/Templates/Project \ Templates/Mac/Application/Command \ Line \ Tool. xctemplate/TemplateInfo. plist
- Modify the description of the OC file header:
/Applications/Xcode. app/Contents/Developer/Library/Xcode/Templates/File \ Templates/Source/Cocoa \ Class. xctemplate
10. Xcode document Installation
(1) Online Installation
(2) copy the document to the document installation directory.
Xcode installation path:/Applications/Xcode. app/Contents/Developer/Documentation/DocSets
Exit and reopen Xcode. If not,/Users/your username/Library/Developer/Shared/Documentation/DocSets checks whether there is a version update with the same name and deletes it.
Note: if there is a document with a higher version in the folder, the document with a lower version is not displayed.
(3) key words in the document
Getting Started: Getting Started
Guides: Guide (what programmers often see)
Reference)
Release Notes: Release Notes
Sample Code: Sample Code
Technical Notes: Technical Description
Technical Q & A: FAQs
Video: Video (mainly WWDC Video)
(4) how to read the document
Quick query documentation:
1. Press and hold the option key and click the key content to be queried.
2. query through Quick Help (double-click the key content to be queried, and then click "Question mark" to view the Quick Documentation)
3. Search directly in the help document
11. Custom code block (shortcut)
How to import shortcuts (code blocks) written by others )?
Copy the code block file directly to the following directory, and then restart Xcode.
/Users/renbo/Library/Developer/Xcode/UserData/CodeSnippets
12. Code grouping
# Pragma mark-grouping code
Function: grouping code. Easy to use for code search and navigation
13. Common Errors
Only the method definition does not implement the method. The following classic error occurs when calling the method: an unknown message is sent to the instance.
Reason: '-[Class Name method]: unrecognized selector sent to instance 0x100301fd0'