luosheng / OpenSim

OpenSim is an open source alternative to SimPholders, written in Swift.
MIT License
1.28k stars 130 forks source link

Fix device parser on Xcode 10.1 #45

Closed Bunn closed 5 years ago

Bunn commented 5 years ago

On Xcode 10.1 there’s a new property on the device json which is not a String: "isAvailable" : true,

This was causing the parser to fail due the [[String:String]] casting.

I changed it to [[String:AnyObject]] and added String casts on the if let.

Ideally this would be solved using codable, but it would require a bigger refactor. I might give it a shot later but I wanted a quick fix to keep using this ASAP :)

RomainQuidet commented 5 years ago

you need to cast 'let availability = deviceJson["isAvailable"] as? Bool' otherwise it fails on my Mac with Xcode 10.1 (10B61)

Bunn commented 5 years ago

@RomainQuidet weird, I'm using Xcode Version 10.1 (10B61) and it works fine screen shot 2018-11-12 at 21 36 57

When I list the devices xcrun simctl list -j devices I see that there's still a String availability in there, so it is just ignoring the isAvailable and using the previous method of checking availability.


        "availability" : "(available)",
        "state" : "Booted",
        "isAvailable" : true,
        "name" : "iPhone SE",
        "udid" : "E5396320-D52B-4061-913D-CAAFB7A938D0",
        "availabilityError" : ""

which then uses this enum

    enum Availability: String {
        case available = "(available)"
        case unavailable = "(unavailable, runtime profile not found)"
    }

I think that using the new isAvailable could be better, but would break backwards compatibility.

If you run this command on your terminal, is the output different?

luosheng commented 5 years ago

Thanks for the PR and sorry for my late reply....

luosheng commented 5 years ago

Codable does seem like a better way.

My other thought is to use FBSimulatorControl as a dependency in place of the json parsing part. I had some attempts in the direct-simctl branch but since my current work doesn't involve iOS development so that didn't go too far.

Also I'm looking for some collaborators of this project. If anyone's interested please let me know.

RomainQuidet commented 5 years ago

@RomainQuidet weird, I'm using Xcode Version 10.1 (10B61) and it works fine screen shot 2018-11-12 at 21 36 57

When I list the devices xcrun simctl list -j devices I see that there's still a String availability in there, so it is just ignoring the isAvailable and using the previous method of checking availability.


        "availability" : "(available)",
        "state" : "Booted",
        "isAvailable" : true,
        "name" : "iPhone SE",
        "udid" : "E5396320-D52B-4061-913D-CAAFB7A938D0",
        "availabilityError" : ""

which then uses this enum

    enum Availability: String {
        case available = "(available)"
        case unavailable = "(unavailable, runtime profile not found)"
    }

I think that using the new isAvailable could be better, but would break backwards compatibility.

If you run this command on your terminal, is the output different?

My bad I moved to isAvailable key with PR #44 so I mixed up the parsing. Your PR is working great.

Bunn commented 5 years ago

Codable does seem like a better way.

My other thought is to use FBSimulatorControl as a dependency in place of the json parsing part. I had some attempts in the direct-simctl branch but since my current work doesn't involve iOS development so that didn't go too far.

Also I'm looking for some collaborators of this project. If anyone's interested please let me know.

@luosheng I'm interested, although I have a busy schedule and have no idea how much of my time I'd be able to invest here, this is an app that I use daily, so I'd be happy to help maintain it :)