-1
比方說,我們有一個自定義對象:如何從自定義對象的數組中獲取特定值?
public struct PosterData : Decodable {
public let filePath : String
public let aspectRatio : NSNumber
public let height : NSNumber
public let width : NSNumber
public init?(json: JSON) {
guard let filePath : String = "file_path" <~~ json,
let aspectRatio : NSNumber = "aspect_ratio" <~~ json,
let height : NSNumber = "height" <~~ json,
let width : NSNumber = "width" <~~ json
else {return nil}
self.filePath = filePath
self.aspectRatio = aspectRatio
self.height = height
self.width = width
}
}
而且我們有一個自定義對象的數組:
var posters:[PosterData] = []
我如何可以遍歷數組在檢索「文件路徑」的所有實例?我試過這個:
for poster in posters {
self.updatePoster(extraPoster:posters[0].filePath)
}
但它所做的是給我第一個對象的「文件路徑」在數組中,而不是其他人。
'poster.filePath'? – Hamish
這樣做,我應該知道這一點 – SwiftyJD