Dyld: Character not found: _OBJC_CLASS _ $ _ NSHTTPURLResponse

I wrote a Swift application with Xcode6 Beta 2 that makes some networks using CFNetwork classes such as NSURLRequestand NSHTTPURLResponse.

The application works fine with iOS 8, but when I try to run it on an iOS 7 device or in a simulator with iOS 7, when I launch the application, I get the following error:

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

I did some research and found out that this is a binding problem. However, I know that the classes I use are already available in iOS 7.

I also tried adding CFNetwork.frameworkto the frameworks in the project settings and setting it as optional, which only caused the application to crash at runtime.

The hard part for me is this: I wrote a test application and just inserted my code, which I used in the main application, and it worked fine. Therefore, the code is probably not a problem.

Removing the application from the simulator / device, cleaning the project and removing Xcode DerivedData did not solve the problem.

Update:

Here is the code that causes the crash:

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
    }
}

But this is just an example. Any use of CFNetwork classes causes the application to crash at startup.

+4
source share
4 answers

This is a known bug with the iOS 8 SDK. As a workaround, move the Foundation.framework file before CFNetwork.framework to the list of frameworks that will be referenced in the project settings.

+11
source

Foundation.framework , CFNetwork.framework . , .

+1

, . , , .

!

0

Foundation.framework , .

, main.m Build Phases → Compile Sources

-, main.m.

0

Source: https://habr.com/ru/post/1546793/


All Articles