1、注释的格式可以通过将代码段拖到xcode左下角的code snippet Library来形成自己的代码格式。
①Xcode provides a bunch of these Code Snippets, which you can find by opening the Utilities View on the right of your window. Near the bottom, you'll find the Code Snippets Library, in addition to the File Template Library (which works similarly). Snippets can be broken down by platform (Mac OS X, iOS) or viewed all together. Look through the available snippets to see how they might save you from repetitive typing in your code.
The provided snippets are useful, but the cause for my adoration stems from being able to add my own snippets to the library. I've found this to be incredibly useful.
-
Find some code you'd like to be a snippet and select it.
-
Drag the selected code to the Snippet Library.
-
Give it a title and optionally a summary. These are used when browsing through the Snippet Library list.
-
Choose a completion shortcut to invoke this snippet. My preference is to use the same letter, repeated three times (ie ddd) because it's quick to type, and it's very unlikely to conflict with another completion symbol in my code. Not only does it avoid direct conflicts, but it also lets me filter down the list of suggestions quickly, so I can accept the completion as quickly as possible.
-
Chose a platform and language, and Completion scope (defaults to the current scope) which lets you choose when the completion shortcut will be available (it wouldn't make sense for your custom initializer method snippet to appear in an Objective-C @interface).
-
Finally, you may wish to edit the snippet code you've added. The mini-editor is syntax highlighted for you, although unfortunately you can't invoke other snippet completion shortcuts here! Sometimes trying this causes Xcode to have an aneurism.
-
Bonus: If you'd like your own “blue code bubbles” to appear as part of your snippet, just type the following in your snippet: <#text in the bubble#> When the user invokes the shortcut for the snippet, the inserted text will contain any blue code bubbles you've included in the hash tags. They can be tabbed back and forth (that is, pressing tab will select the next bubble) and can be accepted by pressing Return. You'll see why these are useful in my examples.
Snippets I find useful
Retain/Assign property: Completion shortcuts of rrr and aaa respectively.
@property (nonatomic, retain) <#type#> *<#name#>;@property (nonatomic, assign) <#type#> <#name#>;
Synthesize for a Custom ivar name: Completion shortcut sss
@synthesize <#property#> = _<#propertyIvar#>;
Useful when you have a custom naming scheme for your instance variables (such as _ivar or mMemberVariable).
Class extension interface: Shortcut eee
@interface <#class name#> ()@end
Pragma line and name: Shortcut ppp. This could alternatively be on one line. Also, when naming your mark label, write out the symbol name in full and it will be CMD+DoubleClickable, ie UITableViewDelegate methods instead ofTable view delegate methods
#pragma mark -#pragma mark <#Label#>
Define macro: Shortcut ddd. Xcode will autocomplete #define for you out of the box, but I find it slower and it doesn't create tabbable bubbles for you for both arguments. I find adding this snippet to be much more efficient.
#define <#name#> <#substitution#>
While code reuse is an incredibly important factor, there are some bits you just can't help but write over and over again. The Code Snippet library can seriously reduce the hassle of this.
②还可以通过以下方式对代码进行标记:
//MARK:
//TODO:
//FIXME:
//???:
2、当xcode中代码无法进行索引时
进入该目录下,删除对应工程文件索引目录即可:open ~/Library/Developer/Xcode/DerivedData
3、测试环境可以真机调试,release版本不可以真机调试
进入这个目录:~/Library/Developer/Xcode/DerivedData,将里面的数据进行删除,然后重启xcode
4、修改程序的Bundle identifier可能会导致程序始终无法启动,一直处在attachApp,需要做的是将模拟器重新启动就可以了,和重启xcode。
5、4.3.3xcode缓存问题很严重,应该属于4.3的一个bug,修改的代码运行起来始终没有变化,重启xcode之后发现之前修改的内容全部没了(另外应该与头文件的引入有问题,相互引用导致文件无法找到目标代码)
6、关于Architectures和Valid Architectures的设置
======================================
Architectures是你打算编译出多少个不同架构的可执行文件来(因为Cocoa的一个应用里面可以包含多个针对不同架构的可执行文件)
Valid Architectures是说编译出来的可执行文件可以在哪些架构的设备上运行,
最终会编译出来多少个可执行文件取决于这两个选项的交集。
所以,如果Architectures设定为armv6,那么不管 Valid Architectures 里面设多少个其他架构,最终都只会生成一个armv6版本的可执行文件。但是,如果Valid Architectures里面没有armv7的话,那么编译出来的可执行文件将不能在armv7的设备上运行,所以,当你装到3GS以后的armv7设备上时,会报那个错:无法在选中的设备上运行。
具体到这个项目,因为大智慧的代码编译成 armv7 就会崩溃,所以只能编译armv6版本,即把Architectures设成armv6这唯一一个值。但是,因为ARM架构是向下兼容的,即新架构的CPU可以运行旧架构的代码,而我们也愿意让编出来的armv6版本可以在新的armv7设备上运行,所以,Valid Architectures里面应该包括 armv6, armv7, armv7s, i386。这个设置固定下来即可,以后不要每次修改。
ARMv7s = iPhone 5, iPad 4
ARMv7 = iPhone 3GS, iPhone 4, iPhone 4S, iPod 3G/4G/5G, iPad, iPad 2, iPad 3, iPad Mini
ARMv6 = iPhone 2G/3G, iPod 1G/2G
i386 = 模拟器
从Xcode 4.5开始,不支持编译armv6的可执行文件了。所以要想支持armv6,必须用4.5之前的版本。但4.5之前的版本没有iOS 6 SDK。
再顺便说一下Build Active Architecture Only 这个选项。
所谓Active Architecture,就是当前插在你电脑上的,并且你在Xcode里面选中了的那个设备的架构。
这个选项主要是给开发阶段用的,因为假设你的应用需要出编译好几个架构的可执行文件,那么每次编译时间就比较长。但是调试的时候,其实只要编译你用来调试的那台机器的架构就够了,其他的都是浪费时间。所以,你可以在开发用的target里把这个选项设成Yes,最终用来打包的target里设成No。这样可以提高效率。
==============================================================
7、出现Undefined symbols for architecture i386错误
①要么在compile source 中没有引入文件。
②要么在link Binary中没有引入应该引入的类库。
PS:stackOverFlow
8、可以通过给文件加编译标签来决定是否使用ARC
- -fno-objc-arc //不使用ARC
- -fobjc-arc //使用ARC
在compiler source中的compiler flags中加入以上字段