3
我是Swift的新手,我在通過屬性檢索數組中的對象時遇到了一些問題。Swift - 通過屬性獲取數組中的對象
請注意,我使用的是Swift 2.0。
我有以下數組;
//Dummy Data prior to database call:
static var listPoses = [
YogaPose(id: 1, title: "Pose1", description: "This is a Description 1", difficulty: Enums.Difficulty.Beginner, imageURL: "Images/Blah1"),
YogaPose(id: 2, title: "Pose2", description: "This is a Description 2", difficulty: Enums.Difficulty.Advanced, imageURL: "Images/Blah2"),
YogaPose(id: 3, title: "Pose3", description: "This is a Description 3", difficulty: Enums.Difficulty.Intermediate, imageURL: "Images/Blah3"),
YogaPose(id: 3, title: "Hello World", description: "This is a Description 3", difficulty: Enums.Difficulty.Intermediate, imageURL: "Images/Blah3")
]
我現在有一個方法,我想通過Id返回一個對象。有人可以告訴我該怎麼做......例如where listPose.Id === Id;
//Returns a single YogaPose By Id:
class func GetPosesById(Id: Int) -> YogaPose{
if(listPoses.count > 0){
return listPoses() ...
}
}
或者這一個:在數組中找到一個對象?](http://stackoverflow.com/questions/28727845/find-an-object-in-array)。 –