質問編集履歴

2

Codeの内のミスを修正

2019/02/15 06:44

投稿

TakamasaIijima
TakamasaIijima

スコア16

test CHANGED
File without changes
test CHANGED
@@ -68,7 +68,7 @@
68
68
 
69
69
  let rawCase = aDecoder.decodeObject(forKey: "PcState") as! Int
70
70
 
71
- self.init(e: CellState(rawValue: rawCase)!)
71
+ self.init(e: PcState(rawValue: rawCase)!)
72
72
 
73
73
  }
74
74
 
@@ -86,7 +86,7 @@
86
86
 
87
87
 
88
88
 
89
- var PCs = Dictionary<Int, PcState>()
89
+ var PCs = Dictionary<Int, ArchivePcState.PcState>()
90
90
 
91
91
  override init() {
92
92
 
@@ -100,7 +100,7 @@
100
100
 
101
101
  }
102
102
 
103
- init(PCs: Dictionary<Int, PcState>) {
103
+ init(PCs: Dictionary<Int, ArchivePcState.PcState>) {
104
104
 
105
105
  super.init()
106
106
 
@@ -122,7 +122,7 @@
122
122
 
123
123
  super.init()
124
124
 
125
- self.PCs = (aDecoder.decodeObject(forKey: "PCs") as? [Int : PcState])!
125
+ self.PCs = (aDecoder.decodeObject(forKey: "PCs") as? [Int : ArchivePcState.PcState])!
126
126
 
127
127
  }
128
128
 
@@ -138,7 +138,7 @@
138
138
 
139
139
  func serialize(Rooms: Room)
140
140
 
141
- let stateDict:[Int:ArchivePcState] = Rooms.PCs as [Int : ArchivePcState]
141
+ let stateDict:[Int:ArchivePcState.PcState] = Rooms.PCs as [Int : ArchivePcState.PcState]
142
142
 
143
143
  let senddata = NSKeyedArchiver.archivedData(withRootObject: stateDict, requiringSecureCoding: false)
144
144
 

1

PC StateをCodingに対応させた

2019/02/15 06:44

投稿

TakamasaIijima
TakamasaIijima

スコア16

test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ```
14
14
 
15
- NSKeyedArchiver.archivedData(withRootObject: dict)
15
+ NSKeyedArchiver.archivedData(withRootObject: dict, requiringSecureCoding: false)
16
16
 
17
17
  //-> デグレートでSIGABRTする
18
18
 
@@ -32,9 +32,45 @@
32
32
 
33
33
 
34
34
 
35
- public enum PcState: Int {
35
+ class ArchivePcState : NSObject, NSCoding
36
36
 
37
+ {
38
+
39
+ public enum PcState: Int {
40
+
37
- case off=0, on=1, stanby=2, hibernate=3
41
+ case off=0, on=1, stanby=2, hibernate=3
42
+
43
+ }
44
+
45
+
46
+
47
+ var e: PcState
48
+
49
+
50
+
51
+ init(e: PcState) {
52
+
53
+ self.e = e
54
+
55
+ }
56
+
57
+
58
+
59
+ func encode(with aCoder: NSCoder) {
60
+
61
+ aCoder.encode(e.rawValue, forKey: "PcState")
62
+
63
+ }
64
+
65
+
66
+
67
+ required convenience init?(coder aDecoder: NSCoder) {
68
+
69
+ let rawCase = aDecoder.decodeObject(forKey: "PcState") as! Int
70
+
71
+ self.init(e: CellState(rawValue: rawCase)!)
72
+
73
+ }
38
74
 
39
75
  }
40
76
 
@@ -102,13 +138,9 @@
102
138
 
103
139
  func serialize(Rooms: Room)
104
140
 
105
- let stateDict:[Int:PcState] = Rooms.PCs as [Int : PcState]
141
+ let stateDict:[Int:ArchivePcState] = Rooms.PCs as [Int : ArchivePcState]
106
142
 
107
- let data = NSKeyedArchiver.archivedData(withRootObject: stateDict) as NSData
143
+ let senddata = NSKeyedArchiver.archivedData(withRootObject: stateDict, requiringSecureCoding: false)
108
-
109
-
110
-
111
- let senddata:Data = data as Data
112
144
 
113
145
  ```
114
146