私は特定のシステム値を返す関数を持っています。 Swift 2.2でうまくいきました。Xcode 8とSwift 3にアップグレードしましたが、今は失敗しています。NSDataをSwift 3のNSStringに変換しますか?
func ioPlatExpertDevString(_ property: String) -> String {
// Start tapping in to the IO Service
let ioPlatformExpertDevice:io_service_t? = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))
var sAnswer = "Not Found"
let cfAnswer:AnyObject! = IORegistryEntryCreateCFProperty(ioPlatformExpertDevice!, "\(property)" as CFString!, kCFAllocatorDefault, 0).takeRetainedValue()
if (cfAnswer != nil) {
let nsAnswer = (cfAnswer as! NSString)
sAnswer = nsAnswer.uppercased
}
// Close the IO Service
IOObjectRelease(ioPlatformExpertDevice!)
return sAnswer
}
以前は、「AnyObject」ではなく「CFData」を使用していました。それは罰金構築しますが、実行時に、私は次のエラーを取得する:
Could not cast value of type '__NSCFData' (0x7fff7b833ec0) to 'NSString' (0x7fff7ac32038).
に
を置き換えますか? –