dyld: Symbol not found: _OBJC_CLASS_$_NSHTTPURLResponse
Asked Answered
L

4

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.

Lymphatic answered 2/7, 2014 at 6:59 Comment(8)
Show the code that causes this error.Rest
I edited the post to include the code.Lymphatic
Try add CFNetwork.framework to Embedded Binaries in Target > General.Each
I added it – didn't change anything.Lymphatic
Can you post more crash log? Also did you try symbolicate crash? May get some information there.Each
I just added the remaining crash log. How do I symbolicate a crash and what for?Lymphatic
Is the app crashes on iOS 8 simulator? (Also I wouldn't set the framework to Optional, it's not a solution)Each
It works fine in iOS 8 Simulator but crashes on iOS 7.Lymphatic
S
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.

Sandpiper answered 2/7, 2014 at 22:21 Comment(1)
Didn't help. Maybe any other suggestion? (Applause
I
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.

Irresoluble answered 29/10, 2014 at 23:15 Comment(0)
L
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!

Lymphatic answered 2/7, 2014 at 17:39 Comment(1)
I would blame it on beta software (Xcode) combined with beta-language (Swift) :) .Rest
M
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.

Michelsen answered 21/7, 2015 at 7:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.