├── CodeSnippet.md ├── Debugger.md ├── KeyBinding.md ├── LISENCE.md ├── README.md ├── SolveCase1.md ├── Workspace.md └── image ├── code_sinppet_buildin_example1.png ├── code_sinppet_buildin_example2.png ├── code_sinppet_buildin_example_core_data.png ├── code_sinppet_buildin_example_kvo.png ├── code_sinppet_creat.png ├── code_sinppet_edit.png ├── code_sinppet_my_example_notification.png ├── code_sinppet_my_example_notification2.png ├── code_sinppet_my_example_property.png ├── code_sinppet_my_example_setter.gif ├── interface_builder_document_setting_iosbuild.jpg └── workspace_simulator_full_screen_example.png /CodeSnippet.md: -------------------------------------------------------------------------------- 1 | < [Back](README.md) 2 | 3 | Code Snippet 4 | ===== 5 | 6 | 代码片段可能是 Xcode 中被忽略最多的功能了,而且很可能你每天都在用它。善用之能极大提高编码效率,应当重视。 7 | 8 | 9 | 内置代码片段 10 | ---- 11 | 12 | 看看下面两幅截图: 13 | 14 | ![内置代码片段示例1](image/code_sinppet_buildin_example1.png) 15 | 16 | ![内置代码片段示例2](image/code_sinppet_buildin_example2.png) 17 | 18 | 眼熟吧。注意到备选项前面的图标了吗,灰色的括号,这表示这个备选项是代码片段提供的。 19 | 20 | 事实上 Xcode 已经为 OS X 和 iOS 开发内置了一组代码片段了,一部分是常用语法的快捷补全,就像上面两个例子那样。剩下的有些示例的味道,比如跟 Core Data 有关的代码片段们: 21 | 22 | ![Core Data 的代码片段](image/code_sinppet_buildin_example_core_data.png) 23 | 24 | 还有 KVO 的: 25 | 26 | ![KVO 的代码片段](image/code_sinppet_buildin_example_kvo.png) 27 | 28 | 很贴心。 29 | 30 | 31 | 自定义代码片段 32 | ---- 33 | 34 | 代码片段是可以创建的,拖拽选中代码段到 Code Snippet Library 即可创建。 35 | 36 | ![拖拽代码创建代码片段](image/code_sinppet_creat.png) 37 | 38 | 在列表中选中指定项按 delete 键即可删除。 39 | 40 | 你可以随时编辑你的代码片段,编辑界面像下面那样: 41 | 42 | ![代码片段编辑界面](image/code_sinppet_edit.png) 43 | 44 | `Completion Shortcut` (自动补全快捷键)是最重要的一项,设置好关键字后就可以在编辑器中输入相应关键字后出现补全提示,否则代码片段只能拖拽到编辑器中使用。`Title` 和 `Summary` 会在补全提示时显示。指定 `Language` 和 `Completion Scopes` 可以让代码片段只在特定区域显示补全提示,在你拖拽创建代码片段时,Xcode 会根据你的拖拽区域自动指定它们。 45 | 46 | 代码片段中的占位符可以按 `<#占位符提示#>` 格式添加。 47 | 48 | 细节: 49 | 50 | > 自动补全快捷键可以包含小部分特殊符号,已知的有 `@`, `$`。除 `@` 外,其他符号虽然也可以填入,但会从其所在位置起导致快捷键失效(比如快捷键为 `$+`,输入 `$` 弹出提示后,再输入 `+`,则提示消失) 51 | 52 | 53 | Tips: 54 | 55 | > 如果自动补全提示没有出现可以试试将 `Language` 改成 `Objective-C`。 56 | 57 | 58 | 用户自定义的代码片段存放于 `~/Library/Developer/Xcode/UserData/CodeSnippets`。 59 | 60 | 61 | 实战:我是如何使用代码片段的 62 | ---- 63 | 目前我在使用的代码片段超过50个,对其非常依赖。这么多项,补全快捷键的管理是个问题,说说我的管理方案。 64 | 65 | 像方法内的代码片段或某些声明直接用正常书写的前几个字符。这样做不像用缩写,没有任何记忆负担,你可以像没有相应代码补全一样正常书写,代码片段的补全会随之出现。举例说明: 66 | 67 | ![几个跟通知有关的代码片段](image/code_sinppet_my_example_notification.png) 68 | 69 | 如上图所示,我定义了几个和通知有关的代码片段,补全快捷键我全都设置成了“NSNotification”,平时使用通知肯定要和 NSNotificationCenter 打交道,没等 NSNotificationCenter 打完补全就出现了: 70 | 71 | ![几个跟通知有关的代码片段](image/code_sinppet_my_example_notification2.png) 72 | 73 | 再如,为了快速声明属性,我有一组代码片段: 74 | 75 | 快捷键 | 代码片段内容 76 | -----|---- 77 | @pa | @property(assign, nonatomic) <#type#> <#name#>; 78 | @pc | @property(copy, nonatomic) NSString *<#var#>; 79 | @pr | @property(readonly, nonatomic) <#type#> <#name#>; 80 | @prw | @property(readwrite, nonatomic) <#type#> <#name#>; 81 | @ps | @property(strong, nonatomic) <#type#> <#name#>; 82 | @pw | @property(weak, nonatomic) <#type#> <#name#>; 83 | @pblock | @property(copy, nonatomic) void (^<#block name#>)(void); 84 | @pi | @property(weak, nonatomic) IBOutlet <#type#> <#name#>; 85 | @pic | @property(strong, nonatomic) IBOutletCollection(<#Class#>) NSArray *<#var#>; 86 | 87 | 用时方便快捷: 88 | 89 | ![属性补全例子](image/code_sinppet_my_example_property.png) 90 | 91 | 如果补全的是一个或多个完整的方法,我通常用 `@` 作为开头,下面是我补全 setter 的动画演示: 92 | 93 | ![setter 补全动画](image/code_sinppet_my_example_setter.gif) 94 | 95 | 你可以到 https://github.com/BB9z/xcode-config/tree/master/UserData/CodeSnippets 获取我的代码片段试一试。 96 | -------------------------------------------------------------------------------- /Debugger.md: -------------------------------------------------------------------------------- 1 | # 调试器使用指南 2 | 3 | ## 调试窗介绍 4 | 5 | 下图是 Xcode 调试窗口,顶部是工具栏,左侧变量区,右侧日志区。 6 | 7 | 8 | 9 | 日志区内,在 (lldb) 处我们可以输入 LLDB 命令。 10 | 11 | ## LLDB 命令 12 | 13 | 如果只学一个命令那就是 po,它可以在断点处执行我们输入的代码,并打印出结果。 14 | 15 | 16 | 17 | 除了比左侧变量列表靠点击查看状态更快以外,更重要的是允许我们在 debug 过程中执行特定代码,比修改代码重新执行要灵活得多。 18 | 19 | 其他常用命令: 20 | 21 | * expr,和 po 类似,打印结果是另一种风格 22 | * bt,打印当前堆栈 23 | 24 | ## 断点 25 | 26 | 27 | -------------------------------------------------------------------------------- /KeyBinding.md: -------------------------------------------------------------------------------- 1 | # 热键 2 | 3 | ## 高频热键 4 | 5 | _强烈建议所有人掌握,以下是默认键位_ 6 | 7 | Command+B,执行编译任务; 8 | 9 | Command+R,运行,Command+.,停止运行; 10 | 11 | Control+Command+E,重命名选中变量(在当前文件中,跨文件修改用重构功能); 12 | 13 | 选中一段文本,Command+E,然后按 Command+G 可以在当前文件中循环查找,+Shift 反向遍历; 14 | 15 | 选中一段文本,Command+E,然后按 Command+4,回车,在项目中搜索; 16 | 17 | Command+Shift+O,快速搜索弹窗,搜索符号或文件直接跳转; 18 | 19 | Command+J,在左侧导航中选中当前打开的文件; 20 | 21 | Command+K,清空终端日志(底部调试器的,清空后完整的日志仍能在 Command+9 日志中找到)。 22 | 23 | 在代码编辑界面: 24 | 25 | Command 点击一个符号,跳转到符号定义的位置; 26 | 27 | Option 点击一个符号,显示符号文档(这时候就体现文档注释的作用了); 28 | 29 | Command+Option 点击一个符号,在另一个标签页展示符号定义的位置; 30 | 31 | 对于 objc 文件,Control+Command+↑(方向键),快速在头文件和源文件间切换。 32 | -------------------------------------------------------------------------------- /LISENCE.md: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 3.0 Unported License 2 | ==== 3 | 4 | _A copy can find at http://creativecommons.org/licenses/by/3.0/legalcode_ 5 | 6 | THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. 7 | 8 | BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. 9 | 10 | 1. **Definitions** 11 | 12 | a. **"Adaptation"** means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License. 13 | 14 | b. **"Collection"** means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(f) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License. 15 | 16 | c. **"Distribute"** means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership. 17 | 18 | d. **"Licensor"** means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License. 19 | 20 | e. **"Original Author"** means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast. 21 | 22 | f. **"Work"** means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work. 23 | 24 | g. **"You"** means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation. 25 | "Publicly Perform" means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images. 26 | 27 | h. **"Reproduce"** means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium. 28 | 29 | 2. **Fair Dealing Rights.** Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws. 30 | 31 | 3. **License Grant.** Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below: 32 | 33 | a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections; 34 | 35 | b. to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified."; 36 | 37 | c. to Distribute and Publicly Perform the Work including as incorporated in Collections; and, 38 | 39 | d. to Distribute and Publicly Perform Adaptations. 40 | 41 | e. For the avoidance of doubt: 42 | 43 | 1. **Non-waivable Compulsory License Schemes.** In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License; 44 | 45 | 2. **Waivable Compulsory License Schemes.** In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor waives the exclusive right to collect such royalties for any exercise by You of the rights granted under this License; and, 46 | 47 | 3. **Voluntary License Schemes.** The Licensor waives the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License. 48 | 49 | The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved. 50 | 51 | 4. **Restrictions.** The license granted in Section 3 above is expressly made subject to and limited by the following restrictions: 52 | 53 | a. You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(b), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(b), as requested. 54 | 55 | b. If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and (iv) , consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4 (b) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties. 56 | 57 | c. Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise. 58 | 59 | 5. **Representations, Warranties and Disclaimer** 60 | 61 | UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. 62 | 63 | 6. **Limitation on Liability.** EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 64 | 65 | 7. **Termination** 66 | 67 | a. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License. 68 | 69 | b. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above. 70 | 71 | 8. **Miscellaneous** 72 | 73 | a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License. 74 | 75 | b. Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License. 76 | 77 | c. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. 78 | 79 | d. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent. 80 | 81 | e. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You. 82 | 83 | f. The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Xcode 完全指南 2 | 3 | 4 | 5 | * [调试器使用指南](Debugger.md) 6 | 7 | ## 武装你的 Xcode 8 | 9 | * [优化工作区](Workspace.md) 10 | * [热键](KeyBinding.md) 11 | * [使用 Code Snippet 加速编码](CodeSnippet.md) 12 | 13 | ## 问题解决 14 | 15 | 这部分还没规划好,先放这。 16 | 17 | * [案例:Xcode 5 下使用 PSTCollectionView](SolveCase1.md) 18 | 19 | ## Contribute 20 | 21 | Any contribute are welcome, e.g.. translate this repo into another language. 22 | 23 | ## Lisence 24 | 25 |

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

26 | -------------------------------------------------------------------------------- /SolveCase1.md: -------------------------------------------------------------------------------- 1 | # 案例:更新 SDK 后 PSTCollectionView 闪退问题解决 2 | 3 | ## 写在前面 4 | 5 | 我发现身边有些这样的人: 6 | 7 | * 遇到错误不看错误信息就开始胡乱试着改正的 8 | * 基础的问题,不看文档,不去搜索就开始找人的 9 | * 遇到问题无从下手的 10 | 11 | 所以,这个系列,我想通过展示自己是如何分析解决问题,给有类似情况的人一些指引,得到启发并提高自身解决问题的能力。 12 | 13 | ## 问题描述 14 | 15 | Xcode 更新到 5 之后,用户反映应用在 iOS 5 上闪退。 16 | 17 | ## 解决步骤及动机分析 18 | 19 | 1. 解决这个问题首先要找到闪退的原因,因为用户没有提供额外的信息,只能自己跑跑看了。 20 | 21 | 2. 在 iOS 5 模拟器上跑了一下,果然一启动就报异常了: 22 | 23 | ```log 24 | *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 25 | reason: 'The NIB data is invalid.' 26 | ``` 27 | 28 | 3. 阅读这段错误信息,异常的原因是“The NIB data is invalid”,nib 文件的格式不正确? 29 | 30 | 4. 因为以前没有这种问题,基本可以断定是升级了 Xcode 5 导致的。首先想到的是检查一下 Stroryboard 的设置: 31 | ![IB 文档的设置](image/interface_builder_document_setting_iosbuild.jpg) 32 | 33 | 5. 其中有一项是 Builds for,里面的设置是 iOS 6 及之后,那八成跟这个选项有关。 34 | 35 | 6. 把这个选项改成 iOS 5 再试,⌘+R 运行,结果产生了编译错误: 36 | 37 | ```log 38 | Class Unavailable: UICollectionViewLayout on iOS versions prior to 6.0 39 | Class Unavailable: UICollectionView on iOS versions prior to 6.0 40 | Class Unavailable: UICollectionReusableView on iOS versions prior to 6.0 41 | ``` 42 | 43 | 7. 看这个错误信息,很清楚的报告了 UICollectionView 只在 iOS 6 之后可用,而我们现在让它编译为 iOS 5 的版本。 44 | 45 | 8. 现在等于我们在未解决第一个问题的情况下又遇到了第二个问题,那我们现在怎么做?有两种方式,先解决第二个问题,然后继续解决前面的问题;另一个是把第二个问题独立出来,继续解决第一个问题,回头再来解决第二个。 46 | 47 | 9. 两种方式没有绝对的优劣,实际上我们先验证了 Builds for iOS 5 的选项可以解决在 iOS 5 运行的问题后再去解决 Collection View 的问题的。 48 | 49 | 10. 验证的办法我想到两个,一种是建一个新项目,改参数去验证,工作量不大,熟练的不用3分钟吧。另一种是临时去掉第二个问题因素的影响,这个例子就是删掉 Storyboard 中的 UICollectionView,完事后通过版本控制工具撤销掉实验性修改,恢复正常进度。 50 | 51 | 11. 解决第一个问题后,就可以开始解决第二个问题了。这个项目我们用第三方的 PSTCollectionView 来让 UICollectionView 支持 iOS 5 的,乍看上去没有什么思路——Stroyboard 必须按 iOS 5 编译,但 UICollectionView 只在 iOS 6 后可用。 52 | 53 | 12. 这种情况目前想到的办法只有完全用代码写。但在动手前还是先搜索一下其他人是如何解决的(至于有没有人遇到的问题不用考虑了,Xcode 5 Beta 了那么长时间要有这问题肯定都遇到了)。 54 | 55 | 13. 搜索的话一般无非 Google、Stack Overflow,但是当时我的直觉是到 GitHub 上看看,也没想太多。现在如果非要列理由的话,大概是: 56 | * PSTCollectionView 项目本身开发比较活跃,而且其维护人 Peter Steinberger 很靠谱,如果这种问题存在,官方应该已经解决的可能性很大。这应该是最重要的考量因素; 57 | * PSTCollectionView 是一个第三方库,受众相对来说较小,到项目的页面上找资源可能更丰富一些。事后在 Stack Overflow 上搜索 PSTCollectionView 的结果才不到两页。 58 | 59 | 14. 于是到项目页面首先看了一下最近的提交情况,提交频度挺高,不错。这么做是确认这个项目还在积极维护中,状态是良好的。 60 | 61 | 15. 然后我更新了一下本地的 clone,试着跑了一下其中的 demo,不过很失望,也存在这种问题。 62 | 63 | 16. 既然最新的版本也这样,那只能到 Pull Requests 和 Issues 看看了。Pull Requests 没有,直接去看 Issues。 64 | 65 | 17. Open 的 Issues 有 50 个左右,而且不少都是很久以前的了,5个月内活跃的只有十多个: 66 | 67 | * Performance Improvement: Hide cells instead of removing them 68 | * Compilation error when used with other common source libraries 69 | * PSTCollectionView crach on IOS 5 when scroll 70 | * Collection View will not scroll when VoiceOver is activated on iPad 71 | * Lazy loaded collection view does not call viewDidLoad prevAttr initialized to nil and can cause an exception in NSDictionary literal 72 | * Crashes on iOS < 6.0 73 | * Decoration views not working properly 74 | * Assertion topLevelObjects.count == 1 is not neccessary (?) 75 | * PSTCollectionViewLayout layoutAttributesForDecorationViewOfKind:indexPath: always uses static elementKind of PSTCollectionElementKindDecorationView 76 | * Selected issue 77 | * Highlight color doesn't disappear 78 | * Line Layout with imageView, odd behaviour 79 | * Issue when subclassing PSUICollectionViewFlowLayout 80 | 81 | 18. 看标题只有“Crashes on iOS < 6.0”这个符合,但进去看了不是我们遇到的问题,其他的也是一样。 82 | 83 | 19. 还不放弃,看看关闭的吧,已经关的 Issues 很多,但因为是最近的问题,所以不必看很多,前两页足够了(除了时间、评论个数也比较有参考价值)。如果以 iOS 5 为关键字的话,稍微“贴边”的有: 84 | 85 | 1. PSTCollectionView crach on IOS 5 when scroll 86 | 2. PSUICollectionViewCell's user interaction flag not working for iOS5 87 | 3. Correctly decoding reuseIdentifier when loading from Nib 88 | 4. How to use PSTCollectionView in Xcode 5 with Base SDK iOS 7, and minimum supported version of iOS 5 89 | 5. compile error in ios5.1 90 | 91 | 这里面真正符合我们问题的其实只有 4 和 5,而且也正是在 4 中得到的答案。链接奉上:PSTCollectionView/issues/344 (已失效) 92 | 93 | 以上就是解决的全过程。 94 | 95 | 多说一句,Cocoa 的错误信息通常都很准确,说的是哪里的问题就是哪里的。 96 | -------------------------------------------------------------------------------- /Workspace.md: -------------------------------------------------------------------------------- 1 | # 优化工作区 2 | 3 | < [Back](README.md) 4 | 5 | ## 一键切换工作区 6 | 7 | 8 | 9 | 设置方法:Xcode 设置 > Behaviors: 点右下角加号建立新 Behavior,点右侧 ⌘ 区域可以设置热键。 10 | 11 | 12 | 13 | 贴下我的配置供参考: 14 | 15 | * 代码模式,Command+1:[Show] navigator [Project],[Hide] debugger,[Hide] inspectors,[Show] toolbar 16 | * UI 模式,Command+2:[Hide] navigator,[Hide] debugger,[Show] inspectors,[Hide] toolbar 17 | * 调试模式,Command+7:[Show] navigator [Debug],[Show] debugger with [Current Views],[Hide] inspectors 18 | * 日志模式,Command+9:[Show] navigator [Local],[Hide] debugger,[Hide] inspectors,[Navigate] to [current log] 19 | 20 | 默认 Command+数字键是在左侧导航 tab 间切换的,设置时会提示热键冲突,点 replace 替换即可。 21 | 22 | ## Tips: 模拟器和 Xcode 全屏并列显示 23 | 24 | 先看效果,虽然损失些编辑空间,但是窗口管理省心了: 25 | 26 | ![模拟器和 Xcode 并列显示](image/workspace_simulator_full_screen_example.png) 27 | 28 | 默认模拟器是不可以全屏显示的,打开一个隐藏开关就能支持全屏了,在终端执行: 29 | 30 | ```shell 31 | defaults write com.apple.iphonesimulator AllowFullscreenMode 1 32 | ``` 33 | -------------------------------------------------------------------------------- /image/code_sinppet_buildin_example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_buildin_example1.png -------------------------------------------------------------------------------- /image/code_sinppet_buildin_example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_buildin_example2.png -------------------------------------------------------------------------------- /image/code_sinppet_buildin_example_core_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_buildin_example_core_data.png -------------------------------------------------------------------------------- /image/code_sinppet_buildin_example_kvo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_buildin_example_kvo.png -------------------------------------------------------------------------------- /image/code_sinppet_creat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_creat.png -------------------------------------------------------------------------------- /image/code_sinppet_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_edit.png -------------------------------------------------------------------------------- /image/code_sinppet_my_example_notification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_my_example_notification.png -------------------------------------------------------------------------------- /image/code_sinppet_my_example_notification2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_my_example_notification2.png -------------------------------------------------------------------------------- /image/code_sinppet_my_example_property.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_my_example_property.png -------------------------------------------------------------------------------- /image/code_sinppet_my_example_setter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/code_sinppet_my_example_setter.gif -------------------------------------------------------------------------------- /image/interface_builder_document_setting_iosbuild.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/interface_builder_document_setting_iosbuild.jpg -------------------------------------------------------------------------------- /image/workspace_simulator_full_screen_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BB9z/Xcode-Complete-Guide/1dba7f486ec67a510dc46ee92dc089a4847748f6/image/workspace_simulator_full_screen_example.png --------------------------------------------------------------------------------