1.ld: warning: directory not found for option 去掉警告的方法html
工程總是提示ld: warning: directory not found for option:xxxxxx 這種提示,一般是因爲添加了第三方SDK,可是後來改了個名字或者去掉了SDK,可是在 Build Settings----->Search Paths----->Library Search Paths 中仍然沒有刪除掉對應的路徑, 因此須要到Library Search Paths和Framework Search Paths中刪除掉警告的路徑,就OK了ios
2.簡單消除 cocoapods第三方庫警告c++
就是在podfile文件裏面加上一行指令 。 正則表達式
inhibit_all_warnings!
若是某警告實在沒法消除,可是又不想讓他顯示,能夠加入預編譯指令swift
好比我已經知道某行會報上面警告了,我就用這個宏把這幾行包住,就不會報引號中-Wunused-variable的警告了xcode
1.方法棄用警告 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" //過時的方法 #pragma clang diagnostic pop 2.不兼容指針類型警告 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wincompatible-pointer-types" //不兼容指針類型 #pragma clang diagnostic pop 3.循環引用警告 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-retain-cycles" //循環引用 #pragma clang diagnostic pop 4.未使用變量警告 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-variable" //未使用的變量 #pragma clang diagnostic pop 5.內存泄漏警告 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" //內存泄漏警告 #pragma clang diagnostic pop
這個-Wunused-variable表明的意思就是 有的東西 你實例化了可是沒有使用, 能夠在工程總中全局配置,在項目中Build Setting里加上這個標示符,能夠連着加的app
三,詳細科學的消除警告ide
1.沒有使用ui
Cannot find protocol definition for 'TencentSessionDelegate'this
2.這種明明都能運行還說我沒有定義的警告,是由於你這個協議雖然定義了,可是你這個協議可能還遵照了XX協議,而後這個XX協議沒有定義致使會報這種警告,因此遇到這種警告要往「父協議」找。 舉個栗子,上面這行就是騰訊受權的庫裏面報的警告,
1
|
@protocol TencentSessionDelegate
|
此協議遵照了TencentApiInterfaceDelegate協議,在TencentOAuth.h類中#import "TencentApiInterface.h" 警告可破
Null passed to a callee that requires a non-null argument
3.這個警告比較新,是xcode6.3開始 爲了讓OC也能有swift的?和!的功能,你在聲明一個屬性的時候加上 __nullable(?能夠爲空)與__nonnull(!不能爲空) 若是放在@property裏面的話不用寫下劃線
1
2
|
@property (nonatomic, copy, nonnull) NSString * tickets;
@property (nonatomic, copy) NSString * __nonnull tickets;
|
或者用宏NS_ASSUME_NONNULL_BEGIN和NS_ASSUME_NONNULL_END 包住多個屬性所有具有nonnull,而後僅對須要nullable的改下就行,有點相似於f-no-objc-arc那種先總體給個路線在單獨改個別文件的思想。 此警告就是某屬性說好的不能爲空,你又在某地方寫了XX = nil 因此衝突了。
Auto property synthesis will not synthesize property 'privateCacheDirectory'; it will be implemented by its superclass, use @dynamic to acknowledge intention
4.他說你的父類實現了setget方法,可是若是你什麼都不寫,就會系統自動生成出最通常的setget方法,請用@dynamic 來認可父類實現的這個getset方法。
Unsupported Configuration: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.
5.通常是storyboard報的警告,簡而言之就是你有的頁面沒有和箭頭所指的控制器連起來,致使最終改頁面可能沒法顯示。
Deprecated: Push segues are deprecated in iOS 8.0 and later
6.iOS8以後呢,不要再用push拖線了,統一用show,他會本身根據你是否有導航欄來判斷走push仍是走modal
Unsupported Configuration: Plain Style unsupported in a Navigation Item
7.導航欄的item 不支持用plain ,那就用Bordered唄。
The launch image set "LaunchImage" has 2 unassigned images.
The app icon set "AppIcon" has 2 unassigned images.
8.幾張圖標仍是啓動圖找不到本身的位置,多是一次導入了所有尺寸圖片,可是右邊的設置只勾了iOS8的 那iOS7尺寸的圖標就會報此警告。刪掉,或者對照右邊匹配。
'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:
9.方法廢除,舊的方法sizeWithFontToSize在iOS7後就廢除了取而代之是boundingRectWithSize方法
Undeclared selector 'historyAction'
10.使用未聲明的方法,通常出如今@selector() 括號裏寫了個不存在的方法或方法名寫錯了。
PerformSelector may cause a leak because its selector is unknown
11.這個和上面相似就是直接把上面那個@SEL拿來用會報這個警告
'strongify' macro redefined
12.這個宏聲明重複,刪一個吧
'UITextAttributeFont' is deprecated: first deprecated in iOS 7.0 - Use NSFontAttributeName
'UITextAttributeTextColor' is deprecated: first deprecated in iOS 7.0 - Use NSForegroundColorAttributeName
'UITextAttributeTextShadowColor' is deprecated: first deprecated in iOS 7.0 - Use NSShadowAttributeName with an NSShadow instance as the value
13.方法廢除,通常一塊兒出現
Code will never be executed
14.他說這代碼永遠也輪不到他執行,估計是有幾行代碼寫在了return以後
Assigning to 'id' from incompatible type 'SXTabViewController *const __strong'
15.通常出如今xxx.delegate = self ,應該在上面遵照協議
Format specifies type 'unsigned long' but the argument has type 'unsigned int'
16.這個警告通常會出如今NSStringWithFormat裏面 前面%d %lu 什麼的和後面填進去的參數不匹配就報了警告
Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead
17.相似於上面,也是format裏面先後寫的不匹配
Method 'dealWithURL:andTitle:andKeyword:' in protocol 'SXPostAdDelegate' not implemented
18.經典警告,遵照了協議,可是沒有實現協議方法。 也可能你實現了只是又加了個參數或是你寫的方法和協議方法名字有點輕微不一樣
Using integer absolute value function 'abs' when argument is of floating point type
19.這個能夠自動修正,就是說abs適用於整數絕對值,要是float取絕對值要用fabsf
Attribute Unavailable: Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
20.有的方法你用的太落後了,也有的方法你用的太超前了。 說這個最大寬度在iOS8以前的系統是要坑的
Too many personality routines for compact unwind to encode
21.你能夠在otherlink 中加入 -Wl,-no_compact_unwind 去掉該警告,根據蘋果的解釋,這個是因爲某些地方 c/c++/oc/oc++混用會形成編譯警告。通常沒有什麼傷害。
Property 'ssid' requires method 'ssid' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation
22.說這個ssid必需要定義個這個屬性的getter方法,若是警告是setSsid就是setter方法, 用@synthesize和@dynamic 都行,一個是讓編譯器生成getter和setter,一個是本身生成,若是你有模型分發或kvc之類的,選@dynamic就行
Unknown escape sequence '\)'
23.未知的轉義序列。 通常有個斜槓再加個東西他都會覺得是轉義字符,一看\)不認識就報警告了,通常正則表達式容易報這種警告
Property 'LoginPort' not found on object of type 'LoginLvsTestTask *'; did you mean to access property loginPort?
24.這種能夠點擊自動修復,是典型的大小寫寫錯了,他提醒了一下。
Variable 'type' is used uninitialized whenever switch default is taken
25.這是出如今switch語句中的警告, 通常多是switch外面定義了個type可是並無初始化(初始化操做都寫在switch的各個分支裏),而後在最後return type。 可是switch的有個分支沒有對type初始化,他說若是你來到這個分支的話,那還沒初始化就要被return。
四 添加警告
1.首先最經常使用的就是 普通警告
#warning TODO
2.若是是本身寫的文件或第三方庫,有了新的接口,而後提示舊的接口廢除的話須要在方法後加上宏
- (void)addTapAction:(SEL)tapAction target:(id)target NS_DEPRECATED_IOS(2_0, 4_0);
3.若是須要在此方法後加上帶信息的警告則須要這麼寫
- (void)addTapAction:(SEL)tapAction target:(id)target __attribute((deprecated("這個接口會爆內存 不建議使用")));
顯示的效果像這樣:
參考:http://www.cocoachina.com/ios/20150914/13287.html