Coder Social home page Coder Social logo

Comments (6)

dennisweissmann avatar dennisweissmann commented on July 24, 2024

Hi,

That sounds awesome! The only reason why this is not yet implemented is that I didn't know that this is possible :)

What do you think about an associated value on the .Simulator case?

Something along the lines of

enum Device {
...
indirect case Simulator(Device)
}

from devicekit.

cacodev avatar cacodev commented on July 24, 2024

I would be fine with whatever you are. I can implement it also if you just let me know what you prefer (trying to build some github cred).

I came across this on stack overflow:

http://stackoverflow.com/questions/26670898/check-ios-simulator-type-and-version

I'm using xcode 7.2 and my simulator is running 9.2. I'm not sure why it would be null for you though?

from devicekit.

dennisweissmann avatar dennisweissmann commented on July 24, 2024

Uh, you already read it! Sorry, I deleted that part of the comment, I was just being dumb ... I called it twice (like getenv(getenv("SIMULATOR_MODEL_IDENTIFIER")) ... dumb me ... Sorry for the confusion!
It's working perfectly right now :)

I can implement it also if you just let me know what you prefer (trying to build some github red).

Of course you can :) I just started playing around a little bit, if you want I can paste it here later and we can discuss it :) If you have a different approach or anything just let me know. In any case you can then go ahead and implement it and send a pull request I you want :)

from devicekit.

dennisweissmann avatar dennisweissmann commented on July 24, 2024

Allright, this is how I solved it: What do you think?

    public init() {
        var systemInfo = utsname()
        uname(&systemInfo)
        let mirror = Mirror(reflecting: systemInfo.machine)

        // I know that reduce is O(n^2) (see http://airspeedvelocity.net/2015/08/03/arrays-linked-lists-and-performance/) but it's *so* nice ❤️ and since we are working with very short strings it shouldn't matter.
        let identifier = mirror.children.reduce("") { identifier, element in
            guard let value = element.value as? Int8 where value != 0 else { return identifier }
            return identifier + String(UnicodeScalar(UInt8(value)))
        }

        func mapIdentifierToDevice(identifier: String) -> Device {
            #if os(iOS)
                switch identifier {
                case "iPod5,1":                                 return iPodTouch5
                case "iPod7,1":                                 return iPodTouch6
                case "iPhone3,1", "iPhone3,2", "iPhone3,3":     return iPhone4
                case "iPhone4,1":                               return iPhone4s
                case "iPhone5,1", "iPhone5,2":                  return iPhone5
                case "iPhone5,3", "iPhone5,4":                  return iPhone5c
                case "iPhone6,1", "iPhone6,2":                  return iPhone5s
                case "iPhone7,2":                               return iPhone6
                case "iPhone7,1":                               return iPhone6Plus
                case "iPhone8,1":                               return iPhone6s
                case "iPhone8,2":                               return iPhone6sPlus
                case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4":return iPad2
                case "iPad3,1", "iPad3,2", "iPad3,3":           return iPad3
                case "iPad3,4", "iPad3,5", "iPad3,6":           return iPad4
                case "iPad4,1", "iPad4,2", "iPad4,3":           return iPadAir
                case "iPad5,3", "iPad5,4":                      return iPadAir2
                case "iPad2,5", "iPad2,6", "iPad2,7":           return iPadMini
                case "iPad4,4", "iPad4,5", "iPad4,6":           return iPadMini2
                case "iPad4,7", "iPad4,8", "iPad4,9":           return iPadMini3
                case "iPad5,1", "iPad5,2":                      return iPadMini4
                case "iPad6,7", "iPad6,8":                      return iPadPro
                case "i386", "x86_64":                          return Simulator(mapIdentifierToDevice(String(UTF8String: getenv("SIMULATOR_MODEL_IDENTIFIER"))!))
                default:                                        return UnknownDevice(identifier)
                }
            #elseif os(tvOS)
                switch identifier {
                case "AppleTV5,3":                              return AppleTV4
                case "i386", "x86_64":                          return Simulator(mapIdentifierToDevice(String(UTF8String: getenv("SIMULATOR_MODEL_IDENTIFIER"))!))
                default:                                        return UnknownDevice(identifier)
                }
            #endif
        }
        self = mapIdentifierToDevice(identifier)
    }

This and changing the case from case Device to indirect case Simulator(Device) should be enough I think (and changing both the iOS and tvOS tests).

What I don't know yet is how we should handle the tests ... Locally we can guarantee that the simulator the tests expects also gets used but I don't know if one can tell travis-ci to use a specific simulator. Do you have any knowledge of such a feature? That's the only problematic point I can think of right now.

If you could also edit the readme file to advertise this feature, that would be great :)

Edit: you need to import func Darwin.getenv, forgot to mention that, sorry!

from devicekit.

dennisweissmann avatar dennisweissmann commented on July 24, 2024

And, of course thanks for not only using but contributing :) It's great to see that people use it and even want to help make it better 👍 :) 🙏

from devicekit.

dennisweissmann avatar dennisweissmann commented on July 24, 2024

Hi Casey,

I just pushed my version! If you still want to contribute, just send me a pull request! (If you have the time it would be great if you could take a look at the readme, since I'm not a native speaker). I'll close this issue for now. Thanks! :)

from devicekit.

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.