dyld:未找到符号:_OBJC_CLASS _ $ _ NSHTTPURLResponse

Pat*_*ick 4 cfnetwork nshttpurlresponse ios7 swift xcode6

我用Xcode6 Beta 2写了一个Swift应用程序,它使用NSURLRequest和等的CFNetwork类进行网络连接NSHTTPURLResponse.

该应用程序适用于iOS 8,当我尝试在iOS 7设备或运行iOS 7的模拟器上运行时,我在启动应用程序时遇到以下错误:

dyld: Symbol not found: _OBJC_CLASS_$_NSHTTPURLResponse
  Referenced from: /Users/patrick/Library/Developer/CoreSimulator/Devices/B0A61F43-A67C-4803-8F5D-77C3972107BE/data/Applications/E0C7C89F-9EEE-4893-BE5B-FCC224F2855D/CheckYourWeather.app/CheckYourWeather
  Expected in: /Applications/Xcode6-Beta2.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks/CFNetwork.framework/CFNetwork
 in /Users/patrick/Library/Developer/CoreSimulator/Devices/B0A61F43-A67C-4803-8F5D-77C3972107BE/data/Applications/E0C7C89F-9EEE-4893-BE5B-FCC224F2855D/CheckYourWeather.app/CheckYourWeather
Run Code Online (Sandbox Code Playgroud)

我做了一些研究,发现这是一个链接问题.不过,我知道我正在使用的类已经在iOS 7中可用了.

我还尝试CFNetwork.framework在项目设置中添加框架并将其设置为可选,这只会导致App在运行时崩溃.

对我来说令人困惑的部分是:我写了一个测试应用程序,只是将我在主应用程序中使用的代码粘贴到它中,它运行得很好.因此代码可能不是问题.

从模拟器/设备删除应用程序,清理项目并删除Xcode的DerivedData没有解决问题.

更新:

这是导致崩溃的代码:

extension NSURLRequest {
    class func plainPostRequest(url: NSURL, httpBody: String) -> NSURLRequest {
        let urlRequest = NSMutableURLRequest(URL: url)
        urlRequest.HTTPMethod = "POST"
        urlRequest.HTTPBody = httpBody.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
        urlRequest.setValue("text/plain", forHTTPHeaderField: "Content-Type")

        return urlRequest
    }
}
Run Code Online (Sandbox Code Playgroud)

但这只是一个例子.任何使用CFNetwork类都会导致应用程序在启动期间崩溃.

use*_*008 11

这是iOS 8 SDK的一个已知错误.作为解决方法,在框架列表中的CFNetwork.framework 之前移动Foundation.framework 以链接到项目设置.