如何使用类中的静态属性传递数据

时间:2017-08-19 08:16:17

标签: swift swift3

1)我想知道在类中使用静态属性传递数据是否可以。

例如:我使用swift类而不是Obj-C类创建一个类:

将此类存储在模型文件夹

class Player {

    static var playerName: String =""
    static var score: Int = 0
    static var Team: String =""
}
VC1中的

我设置

Player.playerName ="Alexander"
VC2中的

: 我访问它:

var strPlayerInAction = Player.playerName

2)如何声明静态类?

static class Player{


}

这样,我可以灵活地传递许多数据。但这会导致任何问题吗?

1 个答案:

答案 0 :(得分:0)

您可以使用结构来实现您想要的效果。

struct Players {
    static var playerName = "name"
}