Created
February 21, 2022 13:37
-
-
Save Hugo6991/18f102e2aa9d4882432557e93c04b2dc to your computer and use it in GitHub Desktop.
04 | Play
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Play 就是一個精彩好球,比如說 LBJ 的 The block, | |
// 所有的卡片只會包含一個 play, | |
// 但同一個 play 可以被很多卡片或是系列包含 | |
pub struct Play { | |
// 每個 play 會有一個獨特的 ID 表示 | |
pub let playID: UInt32 | |
// 每個 play 也會有相應的 metadata, | |
// 這裡的儲存方式是使用一個 string -> string 的 map | |
// 用 key value pairs 代表每個 metadata 屬性的名字及值 | |
// 例如 "playerName" -> "LeBron James" | |
pub let metadata: {String: String} | |
// 創建 struct 時候的初始化 function | |
// 主要就是初始化上述提到的那些 variables | |
init(metadata: {String: String}) { | |
pre { | |
metadata.length != 0: "New Play metadata cannot be empty" | |
} | |
self.playID = TopShot.nextPlayID | |
self.metadata = metadata | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment