Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 3 support? #2

Open
petropavel13 opened this issue Oct 7, 2016 · 3 comments
Open

Swift 3 support? #2

petropavel13 opened this issue Oct 7, 2016 · 3 comments

Comments

@petropavel13
Copy link

Any plans to migrate to Swift 3? As I see, right now, it's best-written native Swift mapping framework.

@bradhilton
Copy link
Owner

Yes, I would like to migrate it to Swift 3. I'm pretty busy right now, but I'll definitely keep you posted.

@petropavel13
Copy link
Author

Hi, @bradhilton! Thanks for your answer!
Last friday I migrated Convertible to Swift 3 and replace Allegro with my fork of Reflection. Currently this fork only supports Carthage, but I would like to add Cocoapods support today. You can take a look (https://github.com/petropavel13/Convertible). Maybe you will use something from it for speed-up your own migration.

@petropavel13
Copy link
Author

petropavel13 commented Oct 11, 2016

Got very strange crash when created object was released.
Here is my code:

struct Post: Convertible {

    let userId: Int
    let id: Int
    let title: String
    let body: String

}

class ViewController: UIViewController {

    fileprivate var post: Post? = nil

    override func viewDidLoad() {
        super.viewDidLoad()

        let rawTitle = "sunt aut facere repellat provident occaecati excepturi optio reprehenderit" as NSString
        let rawBody = "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" as NSString

        let nsDict: [JsonDictionaryKey: Any] = [
            "userId": 1,
            "id": 1,
            "title": rawTitle as String,
            "body": rawBody as String,
        ]

        let swiftDict: [JsonDictionaryKey: Any] = [
            "userId": 1,
            "id": 1,
            "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
            "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
        ]

        do {
            let postFromDict: Post = try Post.initializeWithJson(JsonValue(object: nsDict))
//            let postFromDict: Post = try Post.initializeWithJson(JsonValue(object: swiftDict)) // ok, no crashes
            print(postFromDict)

            self.post = postFromDict
        } catch {
            print(error)
        }

        perform(#selector(ViewController.nullify), with: nil, afterDelay: 1)
    }

    func nullify() {
        post = nil // crash here: swift_unknownRelease
    }

}

Everything works fine if I use Reflection construct:

        let rawTitle = "sunt aut facere repellat provident occaecati excepturi optio reprehenderit" as NSString
        let rawBody = "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" as NSString

        let nsDict: [String: AnyObject] = [
            "userId": NSNumber(value: 1),
            "id": NSNumber(value: 1),
            "title": String(rawTitle) as AnyObject,
            "body": String(rawBody) as AnyObject,
        ]

        do {
            let postFromDict: Post = try construct(dictionary: nsDict)
            self.post = postFromDict
        } catch {
            print(error)
        }

@bradhilton, can you give me any idea where is a problem may be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants