【问题标题】:how to call a parameter from all structs in an array如何从数组中的所有结构调用参数
【发布时间】:2018-03-30 14:42:35
【问题描述】:

在一个名为 DataService.swift 的类中,我创建了一个结构数组,如下所示...

class DataService {
   static let instance = DataService()

   private let bicepWorkouts = [
            Workout(title: "Bicep Machine", imageName: "gloves.png", timeLength: "2:43", videoCode: "_kAlQ5Bh5aY", level: "Beginner", type: "Strength", likes: "5 Likes"),
            Workout(title: "Bicep Curl", imageName: "sixplates.png", timeLength: "1:44", videoCode: "_kAlQ5Bh5aY", level: "Beginner", type: "Strength", likes: "5 Likes")
        ]

    func getBicepWorkouts() -> [Workout] {
        return bicepWorkouts
    }
}

我想从 bicepWorkout 数组中的每个结构调用 Workout videoCode: "_kAlQ5Bh5aY" 到不同的类。 有谁知道如何做到这一点?

提前致谢!

【问题讨论】:

    标签: ios arrays swift struct return


    【解决方案1】:

    你可以试试

     let work1 = DataService.instance.bicepWorkouts[0]
     print("\(work1.videoCode)")
    

    【讨论】:

    • 这成功了!只是给其他有此问题的人的注释,也需要删除私有。
    猜你喜欢
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 2015-04-11
    相关资源
    最近更新 更多