Comments (6)
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.
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.
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.
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.
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.
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)
- Feature Request: provide `.hasUSBCConnectivity` for device with USB-C port by opposition of Lightning HOT 1
- Can't update to DeviceKit v5.2.0 for SPM HOT 12
- Add support for Apple Vision Pro HOT 8
- Use Swift Macros instead of GYB?
- If a device send you its device identifier through network
- Development Team Required
- screenBrightness
- iPhone XR HOT 2
- Please use cocoapod resource_bundles for PrivacyInfo HOT 5
- Library evolution support.
- Spotlights van mees
- Describing use of required reason API HOT 6
- Build DeviceKit as MERGEABLE_LIBRARY
- How about adding properties that provide optical zoom min value? HOT 1
- Add Privacy Manifest HOT 3
- Multiple commands produce PrivacyInfo.xcprivacy HOT 1
- Missing API declaration: NSPrivacyAccessedAPICategoryDiskSpace HOT 6
- Missing API declaration for NSPrivacyAccessedAPICategoryDiskSpace when integrated via SPM HOT 6
- Orientation incorrectly reported as portrait HOT 1
- Add Support for 13 inch iPad devices HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from devicekit.