OSDN Git Service

HMKCShipObjectにNullability指定を行った
authormasakih <masakih@users.sourceforge.jp>
Fri, 6 Jan 2017 13:34:28 +0000 (22:34 +0900)
committermasakih <masakih@users.sourceforge.jp>
Fri, 6 Jan 2017 13:34:28 +0000 (22:34 +0900)
KCD/HMBroserWindowController.swift
KCD/HMFleetViewController.swift
KCD/HMKCShipObject+Extensions.h
KCD/HMKCShipObject.h
KCD/HMShipDetailViewController.swift
KCD/HMShipMasterDetailWindowController.swift
KCD/HMSuppliesCell.swift

index 60a4aa6..6196fcd 100644 (file)
@@ -115,7 +115,7 @@ class HMBroserWindowController: NSWindowController {
             guard let o = try? store?.objects(withEntityName: "Ship", predicate: predicate) else { return nil }
             guard let objects = o as? [HMKCShipObject] else { return nil }
             if objects.count == 0 { return nil }
-            return objects[0].master_ship.name
+            return objects[0].master_ship?.name
         }
     }
     
index 72e1b90..67fa678 100644 (file)
@@ -153,7 +153,8 @@ class HMFleetViewController: NSViewController {
     }
     
     var totalSakuteki: Int {
-        get { return ships.reduce(0) { $0 + ($1.sakuteki_0 as Int) } }
+        get { return ships.reduce(0) { $0 +
+            (($1.sakuteki_0 as? Int) ?? 0) } }
     }
     var totalSeiku: Int {
         get { return ships.reduce(0) { $0 + ($1.seiku as Int) } }
@@ -162,7 +163,7 @@ class HMFleetViewController: NSViewController {
         get { return ships.reduce(0) { $0 + ($1.totalSeiku as Int) } }
     }
     var totalLevel: Int {
-        get { return ships.reduce(0) { $0 + ($1.lv as Int) } }
+        get { return ships.reduce(0) { $0 + (($1.lv as? Int) ?? 0) } }
     }
     var totalDrums: Int {
         get { return ships.reduce(0) { $0 + ($1.totalDrums as Int) } }
@@ -342,8 +343,8 @@ extension HMFleetViewController {
     var repairable: Bool {
         get {
             guard let flagShip = fleet?[0] else { return false }
-            let sTypeId = flagShip.master_ship.stype.id
-            return repairShipIds.contains(sTypeId as! Int)
+            guard let sTypeId = flagShip.master_ship?.stype.id as? Int else { return false }
+            return repairShipIds.contains(sTypeId)
         }
     }
 }
index d9fad2c..3bfe0fb 100644 (file)
@@ -8,19 +8,20 @@
 
 #import "HMKCShipObject.h"
 
+NS_ASSUME_NONNULL_BEGIN
 @interface HMKCShipObject (Extensions)
 
-@property (readonly) NSString *name;
-@property (readonly) NSString *shortTypeName;
+@property (nullable, readonly) NSString *name;
+@property (nullable, readonly) NSString *shortTypeName;
 
-@property (readonly) NSNumber *next;
+@property (nullable, readonly) NSNumber *next;
 
 @property (readonly) NSInteger status;
 @property (readonly) NSColor *statusColor;
 @property (readonly) NSColor *conditionColor;
 
-@property (readonly) NSNumber *maxBull;
-@property (readonly) NSNumber *maxFuel;
+@property (nullable, readonly) NSNumber *maxBull;
+@property (nullable, readonly) NSNumber *maxFuel;
 
 @property (readonly) NSNumber *isMaxKaryoku;
 @property (readonly) NSNumber *isMaxRaisou;
@@ -31,8 +32,8 @@
 @property (readonly) IBOutlet NSColor *planColor;
 
 
-@property (readonly) NSNumber *upgradeLevel;
-@property (readonly) NSNumber *upgradeExp;
+@property (nullable, readonly) NSNumber *upgradeLevel;
+@property (nullable, readonly) NSNumber *upgradeExp;
 
 @property (readonly) NSNumber *totalEquipment;
 
@@ -48,3 +49,4 @@
 @property (readonly) NSNumber *fuelRequiredInRepair;
 
 @end
+NS_ASSUME_NONNULL_END
index da268cc..54ec6fc 100644 (file)
 
 @interface HMKCShipObject : HMKCManagedObject
 
-@property (nonatomic, retain) NSNumber * bull;
-@property (nonatomic, retain) NSNumber * cond;
-@property (nonatomic, retain) NSNumber * exp;
-@property (nonatomic, retain) NSNumber * fleet;
-@property (nonatomic, retain) NSNumber * fuel;
-@property (nonatomic, retain) NSNumber * id;
-@property (nonatomic, retain) NSNumber * kaihi_0;
-@property (nonatomic, retain) NSNumber * kaihi_1;
-@property (nonatomic, retain) NSNumber * karyoku_0;
-@property (nonatomic, retain) NSNumber * karyoku_1;
-@property (nonatomic, retain) NSNumber * kyouka_0;
-@property (nonatomic, retain) NSNumber * kyouka_1;
-@property (nonatomic, retain) NSNumber * kyouka_2;
-@property (nonatomic, retain) NSNumber * kyouka_3;
-@property (nonatomic, retain) NSNumber * kyouka_4;
-@property (nonatomic, retain) NSNumber * locked;
-@property (nonatomic, retain) NSNumber * locked_equip;
-@property (nonatomic, retain) NSNumber * lucky_0;
-@property (nonatomic, retain) NSNumber * lucky_1;
-@property (nonatomic, retain) NSNumber * lv;
-@property (nonatomic, retain) NSNumber * maxhp;
-@property (nonatomic, retain) NSNumber * ndock_time;
-@property (nonatomic, retain) NSNumber * nowhp;
-@property (nonatomic, retain) NSNumber * onslot_0;
-@property (nonatomic, retain) NSNumber * onslot_1;
-@property (nonatomic, retain) NSNumber * onslot_2;
-@property (nonatomic, retain) NSNumber * onslot_3;
-@property (nonatomic, retain) NSNumber * onslot_4;
-@property (nonatomic, retain) NSNumber * raisou_0;
-@property (nonatomic, retain) NSNumber * raisou_1;
-@property (nonatomic, retain) NSNumber * sakuteki_0;
-@property (nonatomic, retain) NSNumber * sakuteki_1;
-@property (nonatomic, retain) NSNumber * sally_area;
-@property (nonatomic, retain) NSNumber * ship_id;
-@property (nonatomic, retain) NSNumber * slot_0;
-@property (nonatomic, retain) NSNumber * slot_1;
-@property (nonatomic, retain) NSNumber * slot_2;
-@property (nonatomic, retain) NSNumber * slot_3;
-@property (nonatomic, retain) NSNumber * slot_4;
-@property (nonatomic, retain) NSNumber * slot_ex;
-@property (nonatomic, retain) NSNumber * sortno;
-@property (nonatomic, retain) NSNumber * soukou_0;
-@property (nonatomic, retain) NSNumber * soukou_1;
-@property (nonatomic, retain) NSNumber * srate;
-@property (nonatomic, retain) NSNumber * taiku_0;
-@property (nonatomic, retain) NSNumber * taiku_1;
-@property (nonatomic, retain) NSNumber * taisen_0;
-@property (nonatomic, retain) NSNumber * taisen_1;
-@property (nonatomic, retain) NSOrderedSet *equippedItem;
-@property (nonatomic, retain) HMKCMasterShipObject *master_ship;
-@property (nonatomic, retain) HMKCSlotItemObject *extraItem;
+@property (nullable, nonatomic, retain) NSNumber * bull;
+@property (nullable, nonatomic, retain) NSNumber * cond;
+@property (nullable, nonatomic, retain) NSNumber * exp;
+@property (nullable, nonatomic, retain) NSNumber * fleet;
+@property (nullable, nonatomic, retain) NSNumber * fuel;
+@property (nullable, nonatomic, retain) NSNumber * id;
+@property (nullable, nonatomic, retain) NSNumber * kaihi_0;
+@property (nullable, nonatomic, retain) NSNumber * kaihi_1;
+@property (nullable, nonatomic, retain) NSNumber * karyoku_0;
+@property (nullable, nonatomic, retain) NSNumber * karyoku_1;
+@property (nullable, nonatomic, retain) NSNumber * kyouka_0;
+@property (nullable, nonatomic, retain) NSNumber * kyouka_1;
+@property (nullable, nonatomic, retain) NSNumber * kyouka_2;
+@property (nullable, nonatomic, retain) NSNumber * kyouka_3;
+@property (nullable, nonatomic, retain) NSNumber * kyouka_4;
+@property (nullable, nonatomic, retain) NSNumber * locked;
+@property (nullable, nonatomic, retain) NSNumber * locked_equip;
+@property (nullable, nonatomic, retain) NSNumber * lucky_0;
+@property (nullable, nonatomic, retain) NSNumber * lucky_1;
+@property (nullable, nonatomic, retain) NSNumber * lv;
+@property (nullable, nonatomic, retain) NSNumber * maxhp;
+@property (nullable, nonatomic, retain) NSNumber * ndock_time;
+@property (nullable, nonatomic, retain) NSNumber * nowhp;
+@property (nullable, nonatomic, retain) NSNumber * onslot_0;
+@property (nullable, nonatomic, retain) NSNumber * onslot_1;
+@property (nullable, nonatomic, retain) NSNumber * onslot_2;
+@property (nullable, nonatomic, retain) NSNumber * onslot_3;
+@property (nullable, nonatomic, retain) NSNumber * onslot_4;
+@property (nullable, nonatomic, retain) NSNumber * raisou_0;
+@property (nullable, nonatomic, retain) NSNumber * raisou_1;
+@property (nullable, nonatomic, retain) NSNumber * sakuteki_0;
+@property (nullable, nonatomic, retain) NSNumber * sakuteki_1;
+@property (nullable, nonatomic, retain) NSNumber * sally_area;
+@property (nullable, nonatomic, retain) NSNumber * ship_id;
+@property (nullable, nonatomic, retain) NSNumber * slot_0;
+@property (nullable, nonatomic, retain) NSNumber * slot_1;
+@property (nullable, nonatomic, retain) NSNumber * slot_2;
+@property (nullable, nonatomic, retain) NSNumber * slot_3;
+@property (nullable, nonatomic, retain) NSNumber * slot_4;
+@property (nullable, nonatomic, retain) NSNumber * slot_ex;
+@property (nullable, nonatomic, retain) NSNumber * sortno;
+@property (nullable, nonatomic, retain) NSNumber * soukou_0;
+@property (nullable, nonatomic, retain) NSNumber * soukou_1;
+@property (nullable, nonatomic, retain) NSNumber * srate;
+@property (nullable, nonatomic, retain) NSNumber * taiku_0;
+@property (nullable, nonatomic, retain) NSNumber * taiku_1;
+@property (nullable, nonatomic, retain) NSNumber * taisen_0;
+@property (nullable, nonatomic, retain) NSNumber * taisen_1;
+@property (nullable, nonatomic, retain) NSOrderedSet *equippedItem;
+@property (nullable, nonatomic, retain) HMKCMasterShipObject *master_ship;
+@property (nullable, nonatomic, retain) HMKCSlotItemObject *extraItem;
 @end
 
+NS_ASSUME_NONNULL_BEGIN
 @interface HMKCShipObject (CoreDataGeneratedAccessors)
 
 - (void)insertObject:(HMKCSlotItemObject *)value inEquippedItemAtIndex:(NSUInteger)idx;
@@ -78,3 +79,4 @@
 - (void)addEquippedItem:(NSOrderedSet *)values;
 - (void)removeEquippedItem:(NSOrderedSet *)values;
 @end
+NS_ASSUME_NONNULL_END
index 5bb2fc0..c422d43 100644 (file)
@@ -34,7 +34,7 @@ class HMShipDetailViewController: NSViewController {
         nc.addObserver(forName: .HMGuardShelterCommandDidUpdateGuardExcape,
                        object: nil,
                        queue: nil) { [unowned self] (notification) in
-                        self.guardEscaped = self.ship?.guardEscaped?.boolValue ?? false
+                        self.guardEscaped = self.ship?.guardEscaped.boolValue ?? false
         }
     }
     
index dc4c9ce..47c185c 100644 (file)
@@ -54,7 +54,7 @@ class HMShipMasterDetailWindowController: NSWindowController {
             d["value"] = v as AnyObject?
             return d
         }
-        equipments = selectedShip.equippedItem.array as NSArray?
+        equipments = selectedShip.equippedItem?.array as NSArray?
     }
     
     @IBAction func applySally(_ sender: AnyObject?) {
index f151d60..bc7188d 100644 (file)
@@ -66,13 +66,13 @@ class HMSuppliesCell: NSCell {
     private var numberOfFuelColoredCell: Int {
         get {
             guard let s = shipStatus else { return 0 }
-            return numberOfColoredCell(withValue: s.fuel as Int, max: s.maxFuel as Int)
+            return numberOfColoredCell(withValue: (s.fuel as? Int) ?? 0, max: (s.maxFuel as? Int) ?? 0)
         }
     }
     private var numberOgBullColoredCell: Int {
         get {
             guard let s = shipStatus else { return 0 }
-            return numberOfColoredCell(withValue: s.bull as Int, max: s.maxBull as Int)
+            return numberOfColoredCell(withValue: (s.bull as? Int) ?? 0, max: (s.maxBull as? Int) ?? 0)
         }
     }
     private func statusColor(withValue value: Int, max: Int) -> NSColor {
@@ -90,13 +90,13 @@ class HMSuppliesCell: NSCell {
     private var fuelStatusColor: NSColor {
         get {
             guard let s = shipStatus else { return redColor }
-            return statusColor(withValue: s.fuel as Int, max: s.maxFuel as Int)
+            return statusColor(withValue: (s.fuel as? Int) ?? 0, max: (s.maxFuel as? Int) ?? 0)
         }
     }
     private var bullStatusColor: NSColor {
         get {
             guard let s = shipStatus else { return redColor }
-            return statusColor(withValue: s.bull as Int, max: s.maxBull as Int)
+            return statusColor(withValue: (s.bull as? Int) ?? 0, max: (s.maxBull as? Int) ?? 0)
         }
     }
 }