Giter Site home page Giter Site logo

Comments (42)

drhr avatar drhr commented on May 12, 2024

I'm seeing this as well. I have two models in two separate files that are referencing the JSON type. If I try to add a third model class in a third file, I run into this compiler crash. But if I lump that third class into one of those first two files, everything's fine.

from swiftyjson.

drhr avatar drhr commented on May 12, 2024

Now when I try this on a brand new project, any reference to JSON causes the seg fault (in 6.0.1 and 6.1 beta 1 and beta 2).

from swiftyjson.

Noobish1 avatar Noobish1 commented on May 12, 2024

I'd suggest just importing SwiftyJSON.swift for now, that seemed work fine for me.

from swiftyjson.

drhr avatar drhr commented on May 12, 2024

That works for now 🍺

from swiftyjson.

LukeTangPL avatar LukeTangPL commented on May 12, 2024

I think it's a Xcode's bug.
How about this:

class Object {
     func method(json: SwiftyJSON.JSON) {
     }
}

from swiftyjson.

broglep-work avatar broglep-work commented on May 12, 2024

I think we experience the same or a similar problem, we have include the Xcode project as dependency.

With Xcode Version 6.1 (6A1052d) the compilation fails with
Segmentation Fault: 11
[snip]

1.  While silgen emitConstructor SIL function @_TFVSC20NSJSONReadingOptionsCfMS_FT_S_ for 'init' at <invalid loc>

We could track it down to the SwiftJSON init method at https://github.com/SwiftyJSON/SwiftyJSON/blob/master/Source/SwiftyJSON.swift#L67-73

When we comment out that part, the segmentation fault does not happen.
Including SwiftJSON directly as swift file also seems to solve the problem. I also think its likely a Xcode bug, and we have filed a bugreport to apple

from swiftyjson.

jeeftor avatar jeeftor commented on May 12, 2024

I think i'm having similar issues

from swiftyjson.

edwellbrook avatar edwellbrook commented on May 12, 2024

I'm seeing this issue as well :(

from swiftyjson.

mwaterfall avatar mwaterfall commented on May 12, 2024

I'm experiencing this even when just importing the swift file

1.  While emitting IR SIL function @_TFFC7App20MUpdateOperation17processCachedDataFS0_FT_T_U_FT_T_ for expression at [/Users/mwaterfall/Projects/.../UpdateOperation.swift:420:25 - line:469:9] RangeText=...

Any fixes about?

from swiftyjson.

lhammond avatar lhammond commented on May 12, 2024

I am also having this issue

from swiftyjson.

adamszeptycki avatar adamszeptycki commented on May 12, 2024

Now I have exactly the same issue, but as long as I use SwiftyJSON in file called Server.swift everything works fine. Even if I add another class in that file (doesn't matter if its pure Swift class or class that is subclass for NSObject) it still works. Did any file apple bug report (for my this is bug with compiler)?

from swiftyjson.

mwaterfall avatar mwaterfall commented on May 12, 2024

Ahh, this is frustrating! Totally unusable, even on Xcode 6.1.1 GM.

from swiftyjson.

dave-kong avatar dave-kong commented on May 12, 2024

Same issue here. @broglep-koubachi 's suggestion is right on.

from swiftyjson.

oldPandaSPUR avatar oldPandaSPUR commented on May 12, 2024

+1 same issue. copying the source file over to my project worked.

from swiftyjson.

kosicki123 avatar kosicki123 commented on May 12, 2024

+1 same issue, copying the source file over the project didn't work for me. Tried all the solutions given in this post, none of them seems to fix the bug. Accepting suggestions!

from swiftyjson.

 avatar commented on May 12, 2024

which files exactly are you adding to your project? because all I had to do was to add 2 files to my project go to Build Settings and make sure the Files are part of my project too. I remember I had to fix a small syntax issue which I really didn't understand why, I can't remember what exactly was but it was not complicated 15 mins top to fix it.

from swiftyjson.

kosicki123 avatar kosicki123 commented on May 12, 2024

I tried adding all files (SwiftJSON.swift, Alamofire.swift and Alamofire-SwiftJSON.swift) to my project, tried to add all the xcodeproj dependencies, tried both at the same time, tried only Alamofire-SwiftJSON and the other 2 physically inside the project...all possible combinations...(also adding to link bynary with libraries)

from swiftyjson.

oldPandaSPUR avatar oldPandaSPUR commented on May 12, 2024

Try to get Alamofire working properly on its own first, the instructions given on their github page are good. That way we can eliminate that as an issue, since I'm also using Alamofire and did not have to copy the source files over to my own project.

Then for SwiftyJSON, I followed the same instructions from Alamofire to setup SwiftyJSON as a submodule. Parts of it worked, but I got segfaults, so thats when I copied SwiftJSON.swift into my project.

from swiftyjson.

 avatar commented on May 12, 2024

hmm thats wierd. I didnt have to add anything about the alamofire. And nothing about adding Link binary. I just added SwiftyJson and some other one like if both files were '.swift files' created by me. tomorrow that I get at the office and see my project Ill check and get back here.

from swiftyjson.

kosicki123 avatar kosicki123 commented on May 12, 2024

Also did this, first of all I got all running and tested with Alamofire, then the same with SwiftyJSON, then when I introduced the Alamofire-SwiftyJSON I made a callback like this, which gave me the error:
func requestLogin(credential: Credential, callback: (retorno: JSON?) -> ())

If I change it to "AnyObject?" it works without the SwiftJSON feature...which is what I want...

from swiftyjson.

yuhua-chen avatar yuhua-chen commented on May 12, 2024

+1 the same issue. the most weird thing is if i add a part of code like this before:

// This is fucking workaround
Alamofire.request(.GET, "", parameters: nil).responseSwiftyJSON { (_, _, _, _) -> Void in 
}.cancel()

and the compiler works....

from swiftyjson.

Jeehut avatar Jeehut commented on May 12, 2024

When I had this issue it helped to just place println(".") at the end of the right method or closure and it worked fine. It really has to be a bug from Apple cause this is weird.

from swiftyjson.

ratkins avatar ratkins commented on May 12, 2024

+1 having this problem on Xcode Version 6.1.1 (6A2006). Manually importing SwiftyJSON and Alamofire-Swifty-JSON as a work-around.

from swiftyjson.

broglep-work avatar broglep-work commented on May 12, 2024

I'd suggest that everybody that has the problem opens a bug report at apple (we have done so), you can reference this github issue in the bug report.
Then lets hope that multiple bug reports will increase the likelihood that this bug will be addressed soon.

from swiftyjson.

Isuru-Nanayakkara avatar Isuru-Nanayakkara commented on May 12, 2024

God, I'm eternally frustrated with Apple's developer tools. I'm getting this issue in Xcode 6.2 beta. Adding the .swift file resolved the issue. I'm going to file a bug report as well.

from swiftyjson.

kostiakoval avatar kostiakoval commented on May 12, 2024

+1 to File a Radar.

I use Alamofire + SwiftJson. I've tried everything and nothing worked work for me
So the quick fix that help me is comment out this peace of code in SwiftyJSON.swift file.

//    public init(data:NSData, options opt: NSJSONReadingOptions, error: NSErrorPointer) {
//        if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error) {
//            self.init(object)
//        } else {
//            self.init(NSNull())
//        }
//    }

from swiftyjson.

danil-z avatar danil-z commented on May 12, 2024

@konstantinkoval thanks,
Your hack did the trick. With unit tests where main app goes as target decency importing SwiftyJSON as a file in main app won't help

from swiftyjson.

rustedivan avatar rustedivan commented on May 12, 2024

Hi all,
I dug into this and have submitted a minimal repro case in PR to /practicalswift/swift-compiler-crashes. It seems the compiler crashes when it hits the default arguments (opt: NSJSONReadingOptions = .AllowFragments) in the JSON initialiser. When a initialization like that is optimised out, the compiler segfaults. It's definitely a bug in swiftc.

It only happens when SwiftyJSON is imported as a module, so you can use the .swift file directly in the meantime.
Another workaround is to make sure the call isn't optimised out (e.g. the .cancel() and println(".") workarounds above.

For SwiftyJSON library code, see if you can omit the default arguments for opt: and errorPointer: somehow. Sucks, but swiftc is still, um, a little wonky and this won't probably be fixed for some time.

from swiftyjson.

raphaelmor avatar raphaelmor commented on May 12, 2024

Hi all,
just a small note to say I use SwiftyJSON.swift directly in a Framework, and it builds fine, but it crashes when I run unit tests (seg fault 11 too). I guess it's because doing that Swifty gets in a module (even if it's not his own) and it is the same bug in swiftc.

from swiftyjson.

Blackjacx avatar Blackjacx commented on May 12, 2024

I have a segfault 11 too when I just include SwiftyJSON.swift in my project. It occurred suddenly after a small refactoring. Before everything was finde. So I think it has nothing to do with the subproject but with some strange swift compiler behaviour.

from swiftyjson.

endel avatar endel commented on May 12, 2024

Same issue here. I'm having a new surprise at each attempt to compile this.

When registering an Alamofire request callback, that's the compiler error I was receiving:

Command failed due to signal: Segmentation fault: 11

After tried what @yuhua-chen suggested, the problem changed, in a very surprising way:

Undefined symbols for architecture x86_64:
  "__TMdV10SwiftyJSON4JSON", referenced from:
      __TFFC7example14ViewController11viewDidLoadFS0_FT_T_U0_FV10SwiftyJSON4JSONT_ in ViewController.o
ld: symbol(s) not found for architecture x86_64

After removing the Alamofire callback, the program do compile, which doesn't help.

from swiftyjson.

rustedivan avatar rustedivan commented on May 12, 2024

@endel: would you be able to share a gist of your crashing/non-crashing code? That sounds like a different segfault that I'd like to minimise and report against swiftc asap. Thanks.

from swiftyjson.

endel avatar endel commented on May 12, 2024

@rustedivan sure, here it is: https://gist.github.com/endel/6e2f9ac7279a6ee42b90

I've written 3 examples to demonstrate what is happening for me:

  1. Runs fine
  2. Segmentation fault
  3. Linker error

I'm using a custom Request class for this.

from swiftyjson.

rustedivan avatar rustedivan commented on May 12, 2024

Excellent, thanks for putting in the effort with the different cases. Swift compiler crashes are collecting over at practicalswift/swift-compiler-crashes so these reports are golden.

from swiftyjson.

Blackjacx avatar Blackjacx commented on May 12, 2024

For me the following caused a segfault while type is an optional:

switch type {
    case .aType:
        // Do Something
    default:
        break
}

and this solved it:

switch type {
    case .Some(.aType):
        // Do Something
    default:
        break
}

from swiftyjson.

sman591 avatar sman591 commented on May 12, 2024

@kostiakoval's workaround solved it for me. I pushed a copy of the changes to https://github.com/sman591/SwiftyJSON/tree/compiler-segfault-workaround in case anyone else wants to try it.

from swiftyjson.

jzarzuel avatar jzarzuel commented on May 12, 2024

Same here :-(
If you remove "options" parameter from init() and pass "AllowFragments" as default value to NSJSONSerialization (cannot be modified as removed as input parameter)... It works.

It's a shame that Apple had relased this faulty compiler (this is one of the many bugs it has)

from swiftyjson.

sferoze avatar sferoze commented on May 12, 2024

I just had this issue! It was hard to track down but essentially once I removed a function that included JSON object from SwiftyJSON class, it crashed my code with the segmentation fault.

So basically if I removed code from the project it crashed.

When I imported SwiftyJSON.swift into my project it started to work.

Here was the stack overflow I posted: http://stackoverflow.com/questions/28623405/why-can-i-not-remove-an-unused-function-from-my-swift-class

from swiftyjson.

broglep-work avatar broglep-work commented on May 12, 2024

We got feedback from apple, they request to test it with Xcode 6.3 and the news swift 1.2 compiler. We still have to migrate our project, so we can't yet test it, so if someone else that has the problem could try it with Xcode 6.3 that would be great

from swiftyjson.

imanzarrabian avatar imanzarrabian commented on May 12, 2024

@broglep-koubachi I had the exact same pb combining Alamofire and SwiftyJSON doing something like this

Alamofire.request(.GET, APIClientConstants.kApiBaseUrl + "/vls/v1/stations", parameters: params).responseJSON { (req, response, json, error) in
            if (error != nil) {
                completionHandler(APIResponseState.Error(error!))
            }
            else {
                var json = JSON(json!)
                completionHandler(APIResponseState.Correct(json))
            }
        }

It wouldn't compile under Xcode 6.1.1 and swift 1.1 but it works with swift 1.2 and Xcode 6.3 after manually updating Alamofire and SwiftyJSON to Swift 1.2 of course

from swiftyjson.

thekie avatar thekie commented on May 12, 2024

+1 Removing the options parameter from init(data:options:error:) worked for me as well.

from swiftyjson.

Isuru-Nanayakkara avatar Isuru-Nanayakkara commented on May 12, 2024

This seems to be fixed in Xcode 6.3.

from swiftyjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.