2016-12-05 82 views
2

我正在使用位置相機。
我在做什麼是當點擊Capture Image按鈕時,我收集字典中的所有位置信息,並進一步將它設置在CFDictionarySetValue中。這是我面臨的問題。
CFDictionarySetValue格式dict, key, value如下:如何在swift 3.0中使用UnSafeRawPointer

CFDictionarySetValue((dictionary)CFMutableDictionary!, (key)UnsafeRawPointer!,(value) UnsafeRawPointer!) 

和我是字典,鍵和值如下:

詞典:

let mutable : CFMutableDictionary = CFDictionaryCreateMutableCopy(nil, 0, metaDict) 

鍵:

kCGImagePropertyGPSDictionary 

let gpsDict : NSDictionary = [kCGImagePropertyGPSLatitude: Int(fabs(loc.coordinate.latitude)), kCGImagePropertyGPSLatitudeRef : ((loc.coordinate.latitude >= 0) ? "N" : "S"), kCGImagePropertyGPSLongitude : Int(fabs(loc.coordinate.longitude)),kCGImagePropertyGPSLongitudeRef : ((loc.coordinate.longitude >= 0) ? "E" : "W") , kCGImagePropertyGPSTimeStamp : formatter.string(from: loc.timestamp), kCGImagePropertyGPSAltitude : Int(fabs(loc.altitude))] 

它看起來像CFDictionarySetValue(mutable, kCGImagePropertyGPSDictionary, gpsDictionary)

而且我得到上面的行錯誤說:"Cannot convert value of type NSDictionary to UnSafeRawPointer! for gpsDictionary"

嘗試了一些方法,但仍然沒有成功。

回答

3

您將NSDictionary作爲參數傳遞給CFDictionarySetValue(...),但期望的類型是類型爲UnSafeRawPointer的指針。第二個參數kCGImagePropertyGPSDictionary也是如此。您傳遞的是NSString而不是指針。

要解決這個問題,請爲這兩個參數創建指針。一種可能的方法:

let pGPSDictionary = Unmanaged.passUnretained(kCGImagePropertyGPSDictionary).toOpaque() 
let pGpsDict = Unmanaged.passUnretained(gpsDict).toOpaque() 
CFDictionarySetValue(mutable, pGPSDictionary, pGpsDict) 

有一個更好的語法創建UnSafeRawPointer s,這我不記得現在。

+0

非常感謝好友,它的工作完美:) – iDeveloper

相關問題