Coder Social home page Coder Social logo

Comments (6)

tonyd256 avatar tonyd256 commented on May 24, 2024

Hi @mikkelharris, I haven't seen this issue before. It might have something to do with subclasses of NSManagedObject. Would you be able to post the code that you're trying to get working in here? It could also be a problem with your setup as well. Either way, this should be something that can work so let's figure it out.

from argo.

mikkelharris avatar mikkelharris commented on May 24, 2024

Thanks for the help @tonyd256

I think it has something to do with how Argo is interacting with my NSManagedObject subclass.  I was able to copy your example from the README and it built fine.  Here’s what I’m working with:

import Foundation
import CoreData
import Argo
import Runes

class Program: NSManagedObject {

    @NSManaged var hollandCodes: String
    @NSManaged var programGroupID: NSNumber
    @NSManaged var summary: String
    @NSManaged var url: String
    @NSManaged var programGroup: ProgramGroup
}

extension Program: JSONDecodable {
    class func create(hollandCodes:String)(programGroupID:NSNumber)(summary:String)(url:String) -> Program{
        return Program(hollandCodes:hollandCodes, programGroupID:programGroupID, summary:summary, url:url)
    }

    class func decode(j:JSONValue) -> Program? {
        return Program.create
        <^> j <| "HollandCodes"
        <*> j <| "ProGroupID"
        <*> j <| "Description"
        <*> j <| "URL"
    }
}

from argo.

tonyd256 avatar tonyd256 commented on May 24, 2024

We've seen issues with class types that aren't final. The workaround is to set the DecodedType of the JSONDecodable protocol. Check out the tests in the Model folder NSURL.swift. Try setting this in the extension on Program:
typealias DecodedType = Program

from argo.

tonyd256 avatar tonyd256 commented on May 24, 2024

You'll also need to make sure NSNumber conforms to JSONDecodable. I haven't done this since I've only considered Int. You can take a look at how Argo does this in Argo/Globals/JSON.swift. And finally, it looks like you're missing the ProgramGroup variable in your create function and in the init inside. Then you'll need to make ProgramGroup JSONDecodable and add it to the bottom of the decode function.

from argo.

mikkelharris avatar mikkelharris commented on May 24, 2024

My issue was in the fact that I was using an NSNumber as one of the argument types in my create function. Instead of throwing an error, Xcode would just hang.

After trying to replicate my situation from scratch, I started receiving an error, "Type 'NSNumber' does not conform to protocol 'JSONDecodable'" for my new test objects.

However when I went back to my original object it would just hang Xcode. Not sure why this is the case but at least I've discovered why it was not working for me

from argo.

tonyd256 avatar tonyd256 commented on May 24, 2024

Argo is pushing the limits of the compiler. If types don't match up properly it usually just hangs as you've been seeing. If you experience it again I would just make sure that all your types that you try to parse from the JSON conform to JSONDecodable, that you've included all the parameters in your create function and in your decode function, and that you've made sure to use the correct Argo operator for arrays and optionals.

Closing this now.

from argo.

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.