iOS常見錯(cuò)誤

-[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance

這個(gè)是由于傳的參數(shù)類型不對(duì)所導(dǎo)致

比如:人家要字符串類型的數(shù)據(jù),你卻傳了個(gè)nsnumber類型的,編譯時(shí)是不會(huì)報(bào)錯(cuò)的,但運(yùn)行結(jié)束后會(huì)崩
單來說,這個(gè)問題分兩個(gè)方面。

  • 錯(cuò)誤如下,這表示是查詢 Library 的時(shí)候出現(xiàn)的異常。

"directory not found for option '-L/..."

解決方法:
依次 Project -> targets -> Build Setting -> Library Search Paths
刪除里面的路徑

  • 錯(cuò)誤如下, 這表示是查詢 Framework 的時(shí)候出現(xiàn)的異常。

"directory not found for option '-F/..."

解決方法:
依次 Project -> targets -> Build Setting -> Framework Search Paths
刪除里面的路徑


解釋

簡(jiǎn)單說一下 Library Search Paths 和 Framework Search Paths 。

Framework Search Paths

官方文檔 能查到的解釋是:

Locating Frameworks in Non-Standard Directories

If your project links to frameworks that are not included in any of the standard locations, you must explicitly specify the location of that framework before Xcode can locate its header files. To specify the location of such a framework, add the directory containing the framework to the “Framework Search Paths” option of your Xcode project. Xcode passes this list of directories to the compiler and linker, which both use the list to search for the framework resources.

Note: The standard locations for frameworks are the /System/Library/Frameworks directory and the /Library/Frameworks directory on the local system.

大意是說,如果你引用的 Frameworks 沒有在標(biāo)準(zhǔn)位置(standard locations),那么,你需要在工程的配置文件里設(shè)置 “Framework Search Paths”, 用來為編譯器(compiler)和連接器(linker)指定搜索路徑。

Library Search Paths

至于 “Library Search Paths”,沒有查到像樣的官方文檔,不過想想內(nèi)容應(yīng)該是差不多的,不過一個(gè)用來搜索Framework,一個(gè)用來搜索Library。

話雖然是這么說,但是什么是Library,什么是Framework,還是很蒙圈。

不過,搜索到了一些博客,來說明這個(gè)問題,現(xiàn)引用在下方。

引用

iOS開發(fā)中的Search Paths設(shè)置

在 iOS 開發(fā)中經(jīng)常遇到一些關(guān)于路徑的設(shè)置,比如引入了百度地圖的 SDK,項(xiàng)目拷貝到其他的電腦上或者多人同時(shí)開發(fā)的時(shí)候容易報(bào) Library Not Found 的錯(cuò)誤,或者是引入第三方庫(kù)比如 ASIHttpRequest/RETableView 經(jīng)常報(bào) #include <> 的錯(cuò)誤這就需要配置一些搜索路徑。

Framework/Library Search Paths

1、Framework Search Paths

附加到項(xiàng)目中的framework(.framework bundles)的搜索路徑,在iOS開發(fā)中使用的不是特別多,通常對(duì)于iOS的開發(fā)來說一般使用系統(tǒng)內(nèi)置的framework。

2、Library Search Paths

附加到項(xiàng)目中的第三方Library(.a files)的搜索路徑,Xcode會(huì)自動(dòng)設(shè)置拖拽到Xcode中的.a文件的路徑,為了便于移植或者是多人協(xié)作開發(fā)一般會(huì)手動(dòng)設(shè)置。

比如對(duì)于設(shè)置百度的地圖的SDK,我們會(huì)設(shè)置如下:

$(SRCROOT)/../libs/Release$(EFFECTIVE_PLATFORM_NAME),其中 $(SRCROOT)宏代表您的工程文件目錄,$(EFFECTIVE_PLATFORM_NAME)宏代表當(dāng)前配置是 OS 還是 simulator

Header Search Path

1、C/C++頭文件引用

在C/C++中,include是變異指令,在編譯時(shí),編譯器會(huì)將相對(duì)路徑替換成絕對(duì)路徑,因此,頭文件的絕對(duì)路徑等同于搜索路徑+相對(duì)路徑。

(1) #include <iostream.h>:引用編譯器的類庫(kù)路徑下的頭文件
(2)#include "hello.h":引用工程目錄的相對(duì)路徑的頭文件

2、(User) Header Search Path

(1)Header Search Path指的是頭文件的搜索路徑。
(2)User Header Search Paths指的是用戶自定義的頭文件的搜索路徑

3、Always Search User Paths

如果設(shè)置了Always Search User Paths為YES,編譯器會(huì)優(yōu)先搜索 User Header Search Paths 配置的路徑,在這種情況下 #include <string.h>, User Header Search Paths 搜索目錄下面的文件會(huì)覆蓋系統(tǒng)的頭文件。



object file (/Users/apple/Library/Developer/Xcode/DerivedData/Test0418-cfpryaixnfxogyfwnsfimebphcxd/Build/Products/Debug-iphonesimulator/libAFNetworking.a(AFAutoPurgingImageCache.o)) was built for newer iOS version (7.0) than being linked (6.0)

原因:
我使用CocoaPods安裝第三方代碼之前,創(chuàng)建的Podfile文件中設(shè)置的ios最低版本是7.0(見下圖)基本可以斷定上面的警告version(7.0)就是指的這個(gè)了.那這個(gè)(6.0)是個(gè)什么鬼?

BACFA35C-6CCD-4DE7-9FA2-9721ABFBC780.png

突然想起來,我剛開始創(chuàng)建項(xiàng)目的時(shí)候選擇的支持系統(tǒng)最低版本是6.0(見下圖)
然后基本確定應(yīng)該就是這的問題了,然后我試著把6.0改為了7.0,果然不出所料,上面類似的警告都沒了

link 錯(cuò)誤

  • 導(dǎo)入文件的.m文件
  • 重復(fù)創(chuàng)建重名的類名
  • 導(dǎo)入的庫(kù)文件不支持模擬器
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容