XCode使用小记与代码管理

一、注释的格式能够经过将代码段拖到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. xcode

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. 缓存

  1. Find some code you'd like to be a snippet and select it. 架构

  2. Drag the selected code to the Snippet Library. app

  3. Give it a title and optionally a summary. These are used when browsing through the Snippet Library list. iphone

  4. 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. ide

  5. 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). 测试

  6. 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. ui

  7. 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. this

Snippets I find useful

Retain/Assign property: Completion shortcuts of rrr and aaa respectively. google

@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:

//???:

二、当xcode中代码没法进行索引时

进入该目录下,删除对应工程文件索引目录便可:open ~/Library/Developer/Xcode/DerivedData

三、测试环境能够真机调试,release版本不能够真机调试

 进入这个目录:~/Library/Developer/Xcode/DerivedData,将里面的数据进行删除,而后重启xcode

四、修改程序的Bundle identifier可能会致使程序始终没法启动,一直处在attachApp,须要作的是将模拟器从新启动就能够了,和重启xcode。


五、4.3.3xcode缓存问题很严重,应该属于4.3的一个bug,修改的代码运行起来始终没有变化,重启xcode以后发现以前修改的内容所有没了(另外应该与头文件的引入有问题,相互引用致使文件没法找到目标代码)


六、关于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。这样能够提升效率。

==============================================================

七、出现Undefined symbols for architecture i386错误

①要么在compile source 中没有引入文件。

②要么在link Binary中没有引入应该引入的类库。

PS:stackOverFlowhttp://stackoverflow.com/questions/6984368/undefined-symbols-for-architecture-i386-objc-class-skpsmtpmessage-refere

八、能够经过给文件加编译标签来决定是否使用ARC

  • -fno-objc-arc              //不使用ARC
  • -fobjc-arc                  //使用ARC

在compiler source中的compiler flags中加入以上字段

九、Could not launch 'app name'   


应用开发相关 若是你也出現了 “Could not launch 'app name'”,No such file or directory (/Users/apple/Libra ry/Developer/Xcode/DerivedData/mytest-ejkagqxooxgmtdfsdoygtyzflibe/Build/Products/Debug-iphoneos/mytest.app/mytest) 這樣的訊息的話,有幾個處理方法 1.刪除DerivedData資料夾法 1.1 彻底離開 Xcode,然後再作下列步驟: 1.2把/Users/apple/Library/Developer/Xcode/DerivedData/下面的東西所有刪除(DerivedData自己不要刪), 1.3再从新啟動 Xcode,再rebuild 2.从新開機法 步驟1沒效的話,把手機全關機,重開機一遍 3.clear法 能够clear一下 4.deployment target OS版本更改 把deployment target改为和實機相同的OS版本 5.改動build path 到Targets下的 Build Settings的Build Locations的Build Products Path的build 把這個地方改为Build Products Path Build/Products 6.从新開啟xcode,从新連結實機 (乍看很笨,其實颇有效) 7.我也沒招了,請本身再去找google大神吧 ps:用高版本xcode 调试低系统版本的 设备 出现这种错误   通常用 第4条解决
相关文章
相关标签/搜索