7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift 2.0 + Xcode 7 Bata 4 で、端末のモデル名を取得する

Last updated at Posted at 2015-07-28
    class func systemModelVersion() -> String {
        var utdName: utsname = utsname()
        uname(&utdName)
        
        let machine = utdName.machine
        let mirror: Mirror = Mirror(reflecting: machine)
        var identifier: String = ""
        
        for children in mirror.children {
            if let value = children.value as? Int8 where value != 0 {
                identifier.append(UnicodeScalar(UInt8(value)))
            }
        }
        return identifier
    }

完璧な私のメモ書きっす!

ちなみに、Xcode 7 Bata 3 だと。。。

    class func systemModelVersion() -> String {
        var utdName: utsname = utsname()
        uname(&utdName)
        
        let machine = utdName.machine
        let mirror: MirrorType = reflect(machine)
        var identifier: String = ""
        
        for index in 0..<mirror.count {
            if let value = mirror[index].1.value as? Int8 where value != 0 {
                identifier.append(UnicodeScalar(UInt8(value)))
            }
        }
        return identifier
    }

と書いていました。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?