5

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.

Patrick
  • 137
  • 1
  • 8

4 Answers4

12

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.

user102008
  • 30,736
  • 10
  • 83
  • 104
2

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.

neeta
  • 63
  • 6
0

I was able to fix the problem by creating a new project and copying all my classes and assets there. Unfortunately I couldn't find out what the actual source of the problem was.

Any alternative solutions are greatly appreciated!

Patrick
  • 137
  • 1
  • 8
0

Moving Foundation.framework would not help so after further investigation the further method helped me.

I was able to resolve the problem by adding main.m file at Build Phases -> Compile Sources

Apparently it couldn't find the main.m file.

Ayan
  • 379
  • 3
  • 7