我有一些難以將我的Swift 2.2應用程序轉換爲Swift 3.0。 我有一些錯誤,我還沒有找到解決方案。目前,我最糟糕的問題是NSFastEnumerationIteration
,我嘗試從JSON獲取記錄,但有這個錯誤我不能。這是我的代碼有問題的截圖:NSFastEnumerationIteration.member Swift 3
0
A
回答
1
在斯威夫特3,您需要指定對象的類型,所以指定數據陣列的類型[[String:Any]]
。
if let dataArr = data as? [[String: Any]] {
for dd in dataArr {
//your code for accessing dd.
}
}
0
對於環只知道你的可變數據是一個數組,不知道別的,所以你需要提供以及的內容的類型您的可變數據:
let dataToParse = dataweneed.data(using: String.Encoding.utf8.rawValue)!
let jsonOptions = [JSONSerialization.ReadingOptions.mutableContainers]
let data = try JSONSerialization.jsonObject(with: dataToParse, options: jsonOptions)
// now For in loop would know that you
// could have an array of dictionaries
if let data = data as? [[String: Any]] {
for dd in data {
// your code
}
}
相關問題
- 1. Swift 3 Swift 4 kishikawakatsumi/SpreadsheetView
- 2. Swift FBSDKLogin Swift 3 AppDelegate更新
- 3. Swift 3 Array Restrictions
- 4. UILongPressGestureRecognizer in Swift 3
- 5. Swift 3 - Hide Elements
- 6. Swift 3 - CFHostScheduleWithRunLoop crash
- 7. rindex in Swift 3
- 8. canBecomeFocus on swift 3
- 9. Swift 3 sqlite bug
- 10. SWIFT 3與MySQL
- 11. SWIFT 3 - MTLResourceOptions.cpuCacheModeDefaultCache
- 12. Swift 3:stringByReplacingCharactersInRange alternatives
- 13. Swift 3 subclassing OperationQueue
- 14. iOS Swift 3 - UIDatePicker
- 15. Swift 3緩存
- 16. Swift 3 references
- 17. Asynchronous swift 3
- 18. ALAssetsLibraryGroupsEnumerationResultsBlock in swift 3
- 19. Swift 3轉換
- 20. Swift 3 UIImageView Order
- 21. Swift 3 - alert style
- 22. CoreData MapKit Swift 3
- 23. Swift 3 NSMuttableArray
- 24. NSLocale Swift 3
- 25. SWIFT 3:的CollectionView
- 26. Swift 3 - InputStream
- 27. Swift 3. NSFetchRequest propertiesToFetch
- 28. JSONSerialization與Swift 3
- 29. Deletebackward()Swift 3
- 30. iOS-Swift 3-SDWebImage
是的,非常感謝!它工作正常! – ewan
歡迎伴侶:) –