在swift 中引入AFNetworking時遇到的問題



剛開始學習swift,什麼都不明白,希望在項目中引用AFNworking,訪問網絡服務,不知道如何使用,先是直接把文件copy到項目中完全沒有用,找了一些 swift調用C 和object_c的例子,試着是要加一個橋接文件,可以成功的調用,但是沒有正常的提示符。

在羣中問了一下,有人提示 cocoapods,好搜索了一下這個東本,發現了:


CocoaPods安裝和使用教程


http://code4app.com/article/cocoapods-install-usage


這個寫的非常好,按其中的操作來做,但遇到這樣的問題:


[!] /usr/bin/git clone 'https://github.com/CocoaPods/Specs.git' master --depth=1


xcrun: error: active developer path ("/Volumes/Xcode/Xcode.app/Contents/Developer") does not exist, use xcode-select to change


沒有文件目錄,找了好多例子,都是一句話:

<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;"><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><span style="background-color: transparent; white-space: inherit;">sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer </span></span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: rgb(43, 145, 175);">即可解決。</span></code>


但我是執行的時候,還是報錯誤,

xcode-select: error: invalid developer directory '/Applications/Xcode.app/Contents/Developer'

沒有目錄,又找找,發現問題是出現在Xcode.app這裏,我用的是Xcode6-Beta.app修改一下命令如下

sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer


成功了:

usertekiMacBook-Air:~ user$ sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer

usertekiMacBook-Air:~ user$ pod search AFNetworking

Setting up CocoaPods master repo

Setup completed (read-only access)


再執行
pod search AFNetworking
看到了正常的結果:

AFNetworking (2.3.1)

   A delightful iOS and OS X networking framework.

   pod 'AFNetworking', '~> 2.3.1'

   - Homepage: https://github.com/AFNetworking/AFNetworking

   - Source:   https://github.com/AFNetworking/AFNetworking.git

   - Versions: 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0, 2.0.3,

   2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4, 1.3.3, 1.3.2,

   1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2, 1.0RC1,

   0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]

   - Sub specs:

     - AFNetworking/Serialization (2.3.1)

     - AFNetworking/Security (2.3.1)

     - AFNetworking/Reachability (2.3.1)

     - AFNetworking/NSURLConnection (2.3.1)

     - AFNetworking/NSURLSession (2.3.1)

     - AFNetworking/UIKit (2.3.1)



-> AFNetworking+AutoRetry (0.0.3)

   Auto Retries for AFNetworking requests

   pod 'AFNetworking+AutoRetry', '~> 0.0.3'

   - Homepage: https://github.com/shaioz/AFNetworking-AutoRetry

   - Source:   https://github.com/shaioz/AFNetworking-AutoRetry.git

   - Versions: 0.0.3, 0.0.2, 0.0.1 [master repo]



-> AFNetworking+streaming (0.5)

   A very quick extension to AFNetworking that adds stream based parsing

   pod 'AFNetworking+streaming', '~> 0.5'

   - Homepage: https://github.com/deanWombourne/AFNetworking-streaming

   - Source:   https://github.com/deanWombourne/AFNetworking-streaming.git

   - Versions: 0.5, 0.4, 0.3, 0.2, 0.1 [master repo]

   - Sub specs:

     - AFNetworking+streaming/Core (0.5)

     - AFNetworking+streaming/Json (0.5)



-> AFNetworking-MUResponseSerializer (1.0.0)

   Automatically serialize JSON response to your object model. It also works

   with NSManagedObjects.

   pod 'AFNetworking-MUResponseSerializer', '~> 1.0.0'

   - Homepage: https://github.com/Ulianko/AFNetworking-MUResponseSerializer

   - Source:   https://github.com/Ulianko/AFNetworking-MUResponseSerializer.git

   - Versions: 1.0.0 [master repo]



-> AFNetworking-RACExtensions (0.1.4)

   AFNetworking-RACExtensions is a delightful extension to the AFNetworking

   classes for iOS and Mac OS X.

   pod 'AFNetworking-RACExtensions', '~> 0.1.4'

   - Homepage: https://github.com/CodaFi/AFNetworking-RACExtensions

   - Source:   https://github.com/CodaFi/AFNetworking-RACExtensions.git

   - Versions: 0.1.4, 0.1.2, 0.1.1, 0.0.1 [master repo]



-> AFNetworking-ReactiveCocoa (0.0.2)

   Make AFNetworking reactive.

   pod 'AFNetworking-ReactiveCocoa', '~> 0.0.2'

   - Homepage: https://github.com/uasi/AFNetworking-ReactiveCocoa

   - Source:   https://github.com/uasi/AFNetworking-ReactiveCocoa.git

   - Versions: 0.0.2, 0.0.1 [master repo]



-> AFNetworking-Synchronous (0.2.0)

   Synchronous requests for AFNetworking

   pod 'AFNetworking-Synchronous', '~> 0.2.0'

   - Homepage: https://github.com/paulmelnikow/AFNetworking-Synchronous

   - Source:   https://github.com/paulmelnikow/AFNetworking-Synchronous.git

   - Versions: 0.2.0, 0.1.0 [master repo]



-> AFNetworking2-RACExtensions (0.0.1)

   AFNetworking-RACExtensions is a delightful extension to the AFNetworking

   classes for iOS and Mac OS X.

   pod 'AFNetworking2-RACExtensions', '~> 0.0.1'

   - Homepage: https://github.com/knshiro/AFNetworking-RACExtensions

   - Source:   https://github.com/knshiro/AFNetworking-RACExtensions.git

   - Versions: 0.0.1 [master repo]



-> CollectionUtils-AFNetworking (1.0.1)

   CollectionUtils additions for AFNetworking.

   pod 'CollectionUtils-AFNetworking', '~> 1.0.1'

   - Homepage: https://github.com/kishikawakatsumi/CollectionUtils

   - Source:   https://github.com/kishikawakatsumi/CollectionUtils.git

   - Versions: 1.0.1, 1.0.0 [master repo]



-> CollectionUtils-AFNetworking-1.3 (1.0.1)

   CollectionUtils additions for AFNetworking 1.3.x.

   pod 'CollectionUtils-AFNetworking-1.3', '~> 1.0.1'

   - Homepage: https://github.com/kishikawakatsumi/CollectionUtils

   - Source:   https://github.com/kishikawakatsumi/CollectionUtils.git

   - Versions: 1.0.1, 1.0.0 [master repo]

usertekiMacBook-Air:~ user$ 


-------------現在是最新版本了,可以在項目中使用了,繼續參考前面的文章使用看看。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章