OSDN Git Service

位置を指定してship_idをセットする関数を追加
authormasakih <masakih@users.sourceforge.jp>
Tue, 14 Mar 2017 11:33:08 +0000 (20:33 +0900)
committermasakih <masakih@users.sourceforge.jp>
Tue, 14 Mar 2017 11:33:08 +0000 (20:33 +0900)
KCD/Deck.swift

index 25b0ee0..2ee3ee0 100644 (file)
@@ -27,7 +27,18 @@ class Deck: KCManagedObject {
 }
 
 extension Deck {
-    private func shipId(ofPosition position: Int) -> Int? {
+    func setShip(id: Int, for position: Int) {
+        switch position {
+        case 0: return ship_0 = id
+        case 1: return ship_1 = id
+        case 2: return ship_2 = id
+        case 3: return ship_3 = id
+        case 4: return ship_4 = id
+        case 5: return ship_5 = id
+        default: fatalError("Deck.setShip: position out of range.")
+        }
+    }
+    func shipId(of position: Int) -> Int? {
         switch position {
         case 0: return ship_0
         case 1: return ship_1
@@ -49,7 +60,7 @@ extension Deck {
     }
     
     subscript(_ index: Int) -> Ship? {
-        guard let shipId = shipId(ofPosition: index) else { return nil }
+        guard let shipId = shipId(of: index) else { return nil }
         return ship(ofId: shipId)
     }
 }