Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dyld: Symbol not found: _OBJC_CLASS_$_NSHTTPURLResponse

I wrote a Swift App with Xcode6 Beta 2 that does some networking using CFNetwork classes such as NSURLRequest and NSHTTPURLResponse.

The App works just fine with iOS 8, still, when I try to run it on an iOS 7 device or in the simulator running iOS 7, I get the following error when starting the App:

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've done some research and found out that it's a linking problem. Still, I know that the classes I'm using are already available in iOS 7.

I also tried to add the CFNetwork.framework to the frameworks in the project settings and set it to optional, which only caused the App to crash during runtime.

The confusing part for me is: I wrote a Test App and just pasted my code I used in the main app into it and it worked just fine. Therefore the code is probably not the problem.

Deleting the App from the Simulator/Device, make a clean on the project and deleting Xcode's DerivedData haven't solved the problem.

Update:

Here's 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 that's just an example. Any use of CFNetwork classes causes the App to crash during start.

like image 579
Patrick Avatar asked Jul 02 '14 06:07

Patrick


2 Answers

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

like image 150
user102008 Avatar answered Oct 18 '22 14:10

user102008


For me just moving the Foundation.framework before CFNetwork.framework doesn't work. I need to close and reopen the project for it to work.

like image 31
neeta Avatar answered Oct 18 '22 12:10

neeta