2. preference settings
Use the "command +," shortcut key or "xcode | Preferences" menu to set outbound call preferences.
(1) Subject and font(Preferences-> fonts & colors)
Select a theme, for example, "Midnight", shift all items in the source Editor/console, and click fonts to set the fonts font. The default font of xcode is Menlo. It can be any other font with the same width as Las or Monaco.
(2) text editing Configuration(Preferences-> text editing)
Editing:
Show line numbers: displays the row number in gutter.
Code folding ribbon: Show folding ribbon.
Page guide at column: displays the split line of a line that supports a maximum of 80 characters.
Indentation:
Prefer indent using: spaces (to maintain consistent visual presentation and line end annotation alignment, spaces are recommended)
Tab width: 4 spaces (tabexpand, 1 tab = 4 spaces)
Indent width: 4 spaces (Auto indent step size = 4 spaces)
(3) SCM(Preferences-> Source Control)
Enable source control: enable/disable the built-in Source Control Manager (SCM) of xcode ).
(4) SDK/simulator (Preferences-> downloads)
Downloads-> components: you can download the SDK and simulator.
(5) Build the output directory(Preferences-> locations)
When default is selected, the Directory of derived data is ~ /Library/developer/xcode/deriveddata.
When relative is selected, the derived data directory is the directory where the current. xcodeproj is located.
When Derm is selected, the derived data directory must be customized.
We do not recommend that you use the absolute path. After writing, you must change the environment or platform and modify the path again. We recommend that you use the relative path (relative ).
3. Read the code
(1) view Navigator
Command + 0: Show/hide left tool panel
Command + 1-8: Project/symbol/find/issue/test/debug/breakpoint/log Navigator
Option + command + 0: Show/hide right tool panel
Option + command + 1/2: show the file/quick help Inspector
(2) view editor Organization
Control + 1: show related items (for example, superclasses/subclasses, callers/callees, protocol implementor/implemented, includes/included ). You can enter real-time search and match.
Control + 2/3: show previous/next history. You can enter real-time search and match.
Control + 4: Show top level items.
Control + 5: Show group files (all files in the current folder ). You can enter real-time search and match.
Control + 6: Show document items (symbols of the current file ). You can enter real-time search and match.
You can directly select the symbol and then "navigate-> reveal in symbol Navigator" to open the symbol list for this interface.
(3) Focus Switch
Command + J: Move focus, which can be used with the mouse and arrow keys. The move focus to a new assistant editor with '+' can quickly open the header file (*. h)/implementation file (*. M ,*. mm ).
Shift + command + J: locate the current file (reveal in project navigator) in the project navigation ).
(4) symbol jump
Control + command + interfaces/interfaces: Switch the header file/implementation file (switch between a source file (. M ,*. mm ,*. CC) and the associated header file (. h )).
Shift + command + O: Open quickly, which allows you to quickly find files and symbols.
Command + Click the symbol selected in the editor: Jump to the symbolic definition (jump to definition ).
Control + command + J: Jump to the definition or implementation of the specified symbol (go to Declaration/definition ). Sometimes, when the project is loading, indexing, or processing files, "command + Click" cannot respond. In this case, try Control + command + J.
Right-click a file in project navigator or choose "file-> show in Finder" to locate the file in finder.
(5) symbol Navigator
Command + Click the non-single level definition symbol in the editor: Show in symbol Navigator:
Filter0: Enter the symbol at the bottom (show symbols with matching name) = filter1 result + filter3 result
Filter1: show only class and Protocol symbols (hide other global symbol types), including the project and system layers.
Filter2: show only project-defined symbols. Filter and display the symbols in the current project. The result of filter2 is a subset of filter1, which is commonly used.
Filter3: show only containers (hide members). filter the symbols that contain this word.
(6) Help
Option + Click to view the help prompt (quick help for selected item) of the selected symbol ).
Option + double-click: Open the help document of the selected symbol.
4. code editing
(1) file | new
Control + command + N: file | new | Workspace
Shift + command + N: file | new | Project
(2) text editing
Command + [/]: Indent forward/backward
Option + command + [/]: Move line up/down
Command +/: comment out the selected code
Parentheses/brackets/braces matching: Double-click a separator (such as (), [], {}, etc.), and xcode selects the matching code block.
(3) eidtor window/TAB Switch
Command + Shift + [/]: Switch the tab
Single-finger sliding (Control + command + ←/→): switch between multiple files opened on a single Tab
(4) code folding
Option + command + hide/→: collapse the current code block
Option + Shift + command + methods/→: collapse all code blocks in the file (methods/functions)
(5) console & Scheme
Shift + command + Y: Show/hide the debug Area)
Option + command + R: Edit Scheme)
(6) gutter & RIBBON
Focus column: the gray depth is related to the depth of code nesting. You can hover the mouse over to highlight the corresponding code block on the right, and click the corresponding code block on the right to collapse (Code folding ).
Note: from left to right, the navigation pane is "> edge column (gutter)> focus column (Focus ).
Ribbon)-> code editor window (Standard editor )".
(7) Auto completion
ESC (command +.): Call/hide auto in the context of the current input
Completion prompt: select the option in the prompt by using the up and down arrow keys, and select enter (return). The tab can be a match. The tab can be moved between placeholders.
Enter the objective-C object and] to automatically complete infixnatation.
(8) Find & replace
Command + F: Search for the current file.
Option + command + F: Replace the current file.
Find: You can specify the search content (text/References/Definitions/regular expression );
Magnifier: You can view the latest search history from the drop-down list;
In Project: Query range (you can specify a group );
Text: matching rule (you can specify containing, matching, starting with, ending );
Case: case sensitive (matching/ignoring can be specified ).
Shift + command + f (command + 3): global search. You can also right-click the symbol (Control + click)-> Find selected text in workspace...
Option + Shift + command + F: Global replacement.
5. Assistant Editor)
The assistant editor is similar to the Code definition window in VC.
Option + command + enter: Open assistant editor.
Command + enter: close assistant editor.
When you use a shortcut key to switch or jump, if you press option at the same time, you can open the corresponding file or symbol (for optional navigation (option-clicking or option-choosing a file) in the auxiliary editing window ), opens the file in a new assistant editor pane .). If you operate in the secondary window, it is opened in the main window (Standard editor.
Option + click the file selected in project navigator: Open the selected file in the auxiliary editing window.
Option + command + Click the symbol selected in the editor: in the auxiliary editing window, open the symbolic definition (jump to definition in assistant editor ).
Option + Control + command + methods/methods: Open the corresponding header file (*. h)/implementation file (*. M, *. Mm, *. CC) in the auxiliary window ).
When you click to view the files or symbols selected by SHIFT + command + O, Shift + command + f (command + 3), you can press option to open them in the auxiliary editing window.
In Control + 1 ~ 6, you can open the selection result in the auxiliary editing window by pressing option at the same time.
If you press shift when you press option, a navigation pane is usually displayed. You can choose new window/TAB/Assistant-editor to open it.
Foroption-shift navigation (option-shift-click or option-shift-choose a file), xcode displays a graphical navigation chooser showing the current layout. the chooserprompts you to open the file in anyopen editor pane in any window and tab, or to open the file in anew editor pane, window, or tab.
6. Build setting macros)
(1) view the environment variables macro
Run the command line to enter the helloworld project directory, execute the xcodebuild command, and add the "-showbuildsettings" parameter:
$ Xcodebuild-Project helloworld. xcodeproj-target helloworld-configuration debug-showbuildset.pdf> xcodebuild_showbuildsettings.txt
Xcodebuild_showbuildsettings.txt stores the build settings for action build and target "helloworld", where dump all environment variables.
(2) Some environment variables of xcode5 (Mac OS X 10.9)
Convention 1 :~ = The Home Directory of the current account, for example, "/users/faner ".
Convention 2: Build basic path: build_path = ~ /Library/developer/xcode/deriveddata/build. You can use "file-> Project Settings" to view the derived data location.
Convention 3: Build setting macros reference format: $ {macro}, which is the same as the syntax in build phases run script.
The following is a list of common environment variables selected from xcodebuild_showbuildsettings.txt.
(A) arch & Platform & SDK
Archs = i386
Current_arch = i386
Platform_dir =/applications/xcode. APP/contents/developer/platforms/MacOSX. Platform
Platform_name = MacOSX
Sdkroot =/applications/xcode. APP/contents/developer/platforms/MacOSX. Platform/developer/sdks/macosx10.9.sdk
Sdk_dir =/applications/xcode. APP/contents/developer/platforms/MacOSX. Platform/developer/sdks/macosx10.9.sdk
Sdk_name = macosx10.9
(B) Project & Source
Project = helloworld
Project_dir = ~ /Projects/learn objective-C/helloworld
Project_file_path =$ {project_dir}/helloworld. xcodeproj
Project_name = helloworld
Source_root =$ {project_dir}
Srcroot =$ {project_dir}
(C) Build & Configuration
Build_dir = build_path/products
Build_root = build_path/products
Built_products_dir = build_path/products/debug
Configuration = debug
Configuration_build_dir = build_path/products/debug
Configuration_temp_dir = build_path/intermediates/helloworld. Build/debug
(D) Product & target
Product_name = helloworld
Product_type = com. Apple. product-type.tool // Project template: command line tool
Target_build_dir = build_path/products/debug
Target_name = helloworld
(3) set Environment Variables
In product-> edit Scheme (option + command + r)-> arguments-> environment variables, you can add custom environment variables (name and value ).
7. Run debugging
(1) Console
Shift + command + Y: Show/hide the debug Area)
Shift + command + K: Clear the console (clean)
(2) Build
Product-> edit Scheme (option + command + r)-> Info-> build configuration: select the generated version (debug or release)
Command + B: Build (buid)
(3) Target
A target is a product built in a project. It contains all the files for building the product and how to build the configuration of the product.
A target that defines the build process becomes a scheme. You can define six build processes of the target in scheme: build/run/test/profile/analyze/archive.
Product-> edit Scheme (option + command + r)-> Manage schemes can be used to configure the six construction processes of scheme (including info, arguments, and options ).
Select an xcodeproj (for example, QQ. xcodeproj) in project navigator to go to the project setting page. Click the show/hide project and targets List icon on the left:
Click the targets item to set build settings for each target, and right-click to delete the target.
(4) issue & errors
When there are too many compilation errors (errors) and warnings (warning), only the compilation errors are displayed:
Click the exclamation point at the bottom to show only compilation errors and ignore the compilation warning:
(5) Run
Command + R: Run, which may be compiled first. If you press control to directly run the product (run without building) built last time ).
Command +.: Stop)
(6) breakpoint
Command + \: set or cancel a breakpoint for the current row. Click the blue breakpoint to enable or disable the breakpoint for the current row.
Command + Y: globally activate or disable all breakpoints. Activation enters the debugging mode (in this case, the breakpoint is visible in blue ).
You can right-click the breakpoint/warning in the edge column (gutter) to call out reveal in breakpoint/issue navigator.
Trick: Edit breakpoint ):
Condition: Set the trigger condition for a breakpoint. For example, "I = 3" (note that no space is allowed) indicates that the breakpoint will be triggered when I is equal to 3.
Ignore: specifies the number of times a breakpoint is ignored before it is interrupted. If it is set to 5, it indicates that it is triggered only when the breakpoint is met for 6th times.
Action: Set the action when a breakpoint is triggered. It can be debugger command, log message, shell command, or sound.
For example, you can set the following debugger command:
(1) memory buffer value for reading STD: String Sig: Mem read Sig. c_str ()-C Sig. Size ();
(2) print nsdata instance Sig: Po SIG
(7) debug
F6: Next Step over, one-step debugging step by step without entering the function body.
(FN +) F7: enters the (step into) function body. It may conflict with multimedia keys, so FN is required.
(FN +) F8: jump out of the (Step out) function body. It may conflict with multimedia keys, such as calling iTunes. Therefore, FN is required.
Control + command + Y: continue to run the command on a breakpoint (continue.
Trick: Move the instruction pointer ):
During breakpoint debugging, you can move the green pointer arrow (line 47) to another line (line 49) or other breakpoint (line 51) for redirect execution.
(8) Watch
Shift + command + M: Debug workflow-> View memory.
Command + K: Debug workflow-> clear console.
Debug workflow-> showdisassembly when debugging to debug assembly commands.
Trick: Change memory value while debugging ):
During debugging, you can right-click a variable in the debugging window (debug area, which can be called by SHIFT + command + Y) at the bottom, in addition to viewing memory/view value, you can also select Edit value to edit the value of the memory variable during runtime.
This manual setting of the specified value is useful in debugging bugs that are difficult to reproduce or performing a boundary test. It can avoid repeated value re-Compilation When verifying a problem.
(9) lldb debugging command:
N/next: Step over;
S/step: Step;
Finish: Step out;
C/continue: goto next breakpoint;
Expr/expression: Evaluate a C/objc/C ++ expression (dynamic execution of C/objc/C ++ expressions );
P/print/expr/expression: print as a C/C ++ basic variable;
Po/expr-O/expression-O: print as an objective-C object;
Call: Call. In fact, the P/Po Post-expression (expression) also has the function of calling. Generally, call is used only when explicit output is not required or no return value is required for dynamic debugging and insertion of call code.
For example, you can set a breakpoint in viewdidload, and then enter the following command when the program is interrupted:
1 |
call [self.view setBackgroundColor:[UIColor redColor]] |
Continue to run the program. The background color of the view changes to red!
Bt (backtrace): prints the current call stack (crash stack). "BT all" can print the stacks of all threads (equivalent to the debug session navigation of command + 6 ).
Image: it can be used for addressing. There are multiple combined commands. A more practical method is to find the code (line) Location corresponding to the stack address.
For example, a uitableview has two sections in total when it references currentsection. when index is greater than or equal to 2, [uitableview rectforheaderinsection:] The call is abnormal. You can use expr to dynamically change the value to create a crash scenario for simulated debugging.
At this time, the crash console BT displays an exception in the Application Layer Code "0x00d055b8-[facategorytableview facategorysectionheaderdidtouched:] + 744" (where 0x00d055b8 is the offset of the current stack (code segment, 744 is the stack frame offset -- the offset of the PC pointer to the function entry ).
Which line of code is called in the facategorytableview. M file? In this case, the code segment offset address (0x00d055b8) in the call stack of Bt is connected through "image lookup -- Address" to locate the code line location of the abnormal call.
Syntax:
Memory read []
Command Options usage:
Size specifies the size of the memory block (Block/item). The default value is 1 byte.
-- Size): the size in bytes to use when displaying with the selected format.
Count specifies the number of memory blocks (blocks/items), which can be used with the starting address.
-C (-- count): the number of total items to display.
Format specifies the content display format, which is the same as print: C-Char, S-string, D-decimal, X-hex.
-F (-- format): specify a format to be used for display.
Command samples:
(A) starting and ending addresses
(Lldb) MEm read 0x10b88f0c 0x10b88f0c + 9
0x10b88f0c: 39 38 37 36 35 34 33 32 31 987654321
(B) starting address + memory block count
(Lldb) MEm read 0x10b88f0c-C 9
0x10b88f0c: 39 38 37 36 35 34 33 32 31 987654321
(C) starting address + memory block size + memory block count (dump hex format)
(Lldb) memory read-S 1-f x-C 9 0x10b88f0c
0x10b88f0c: 0x39 0x38 0x37 0x36 0x35 0x34 0x33 0x32
0x10b88f14: 0x31
(D) starting address + memory block size + memory block count (dump char format)
(Lldb) memory read-S 1-f c-c 9 0x10b88f0c
0x10b88f0c: 987654321
(E) starting address + memory block size + memory block count (dump string format)
(Lldb) MEm read 0x10b5cf2c-f s-C 1
0x10b88f0c: "987654321"
(F) starting address + memory block size + memory block count (dump int format)
(Lldb) memory read-S 4-f x-C 3 0x10b88f0c
0x10b88f0c: 0x36373839 0x32333435 0x0000f0031
Syntax: memory write
[[...]
(10) Enable nszombieenabled to debug exc_bad_access
When you send messages to released objects (90% may be release for objects with 0 reference count) or release autorelease objects, an error such as exc_bad_access will occur.
By default, xcode does not show you which code should not use released objects, or the release is incorrect.
Product-> edit Scheme (option + command + r)-> diagnostics, select "enable zombie objects" after "objective-c ".
After the nszombieenabled environment variable is set, an object is converted to _ nszombie when it is destroyed. After nszombieenabled is set, when you send a message to a released object, this object does not only report exc_bad_access crash, an error message is also released, and then disappears in a predictable way that can generate a debug breakpoint. Therefore, we can find the specific or approximate object to be released or referenced by the error.
Note: nszombieenabled can only be used during debugging. Do not forget to remove it when the product is released, because nszombieenabled does not actually release the memory of the dealloc object. You are solely responsible for enabling it!
Reference
Xcode overview-about xcode, xcode keyboard shortcuts and gestures
Xcode key bindings & gestures tips for improving xcode Efficiency
Xcode5.1 offline installation, xcode plug-in, VIM editor for xcode, VIM command illustration and xvim usage
Xcode file organization, xcode setting command line startup parameters
Xcode environment variables and path settings xcode build output directory
From VC to xcode workspace & subproject & target
Xcode static Library Creation xcode4 static Library Creation 1 xcode4 static Library Creation 2
Create framework under xcode4.3 xcode add dependent static library project
Building static libraries with the iPhone SDK static libraries and cross-project references
Start developing IOS apps today
Use xcode to create a hello World project, use xcode5 and interface builder to create a hello World app
Lldb Quick Start Guide lldb to GDB command map xcode GDB/lldb debugging command
Xcode lldb debug tutorial, lldb debugging command, IOS application crash log secrets, and operating your iOS Application Log
(Via: a blog that once dreamed of leaving the world with a sword)
Basic xcode operations
Basic xcode operations