• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

macOSのスクリーンショットの保存場所を変更するメニュバーエクストラ


Commit MetaInfo

Revisiona26a3825aea74e73519bbaf1d52be06ba2d6178c (tree)
Time2017-04-22 19:55:01
Authormasakih <masakih@user...>
Commitermasakih

Log Message

LimitedArrayをシリアライズするLimitedArraySerializerを追加

Change Summary

Incremental Difference

--- a/GoInto.xcodeproj/project.pbxproj
+++ b/GoInto.xcodeproj/project.pbxproj
@@ -13,6 +13,8 @@
1313 F40EB6CA1EA1D7B500FEE444 /* ImageType.plist in Resources */ = {isa = PBXBuildFile; fileRef = F40EB6C91EA1D7B500FEE444 /* ImageType.plist */; };
1414 F40EB6D01EA26BEC00FEE444 /* ActionListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40EB6CF1EA26BEC00FEE444 /* ActionListener.swift */; };
1515 F40EB6D21EA2F28100FEE444 /* Screenshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40EB6D11EA2F28100FEE444 /* Screenshot.swift */; };
16+ F463F6D91EAA3B8F00FAB2E3 /* CollectionSerializerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F463F6D81EAA3B8F00FAB2E3 /* CollectionSerializerTest.swift */; };
17+ F463F6DB1EAA3C9700FAB2E3 /* LimitedArraySerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F463F6DA1EAA3C9700FAB2E3 /* LimitedArraySerializer.swift */; };
1618 F47B06EB1E9A5DF9006711D9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47B06EA1E9A5DF9006711D9 /* AppDelegate.swift */; };
1719 F47B06EF1E9A5DF9006711D9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F47B06EE1E9A5DF9006711D9 /* Assets.xcassets */; };
1820 F47B06FD1E9A5DF9006711D9 /* GoIntoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47B06FC1E9A5DF9006711D9 /* GoIntoTests.swift */; };
@@ -45,6 +47,8 @@
4547 F40EB6C91EA1D7B500FEE444 /* ImageType.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ImageType.plist; sourceTree = "<group>"; };
4648 F40EB6CF1EA26BEC00FEE444 /* ActionListener.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionListener.swift; sourceTree = "<group>"; };
4749 F40EB6D11EA2F28100FEE444 /* Screenshot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Screenshot.swift; sourceTree = "<group>"; };
50+ F463F6D81EAA3B8F00FAB2E3 /* CollectionSerializerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionSerializerTest.swift; sourceTree = "<group>"; };
51+ F463F6DA1EAA3C9700FAB2E3 /* LimitedArraySerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LimitedArraySerializer.swift; sourceTree = "<group>"; };
4852 F47B06E71E9A5DF9006711D9 /* GoInto.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GoInto.app; sourceTree = BUILT_PRODUCTS_DIR; };
4953 F47B06EA1E9A5DF9006711D9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5054 F47B06EE1E9A5DF9006711D9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -112,6 +116,7 @@
112116 F47B07171EA10A88006711D9 /* QuitItem.swift */,
113117 F40EB6CF1EA26BEC00FEE444 /* ActionListener.swift */,
114118 F4D346931EA644170031AFB3 /* LimitedArray.swift */,
119+ F463F6DA1EAA3C9700FAB2E3 /* LimitedArraySerializer.swift */,
115120 F47B06EE1E9A5DF9006711D9 /* Assets.xcassets */,
116121 F47B06F31E9A5DF9006711D9 /* Info.plist */,
117122 F40EB6C91EA1D7B500FEE444 /* ImageType.plist */,
@@ -126,6 +131,7 @@
126131 isa = PBXGroup;
127132 children = (
128133 F4DBE9271EA7864B00CEB984 /* LimitedArrayTest.swift */,
134+ F463F6D81EAA3B8F00FAB2E3 /* CollectionSerializerTest.swift */,
129135 F47B06FC1E9A5DF9006711D9 /* GoIntoTests.swift */,
130136 F47B06FE1E9A5DF9006711D9 /* Info.plist */,
131137 );
@@ -246,6 +252,7 @@
246252 F47B07181EA10A88006711D9 /* QuitItem.swift in Sources */,
247253 F40EB6C81EA1CD7A00FEE444 /* ImageTypeItem.swift in Sources */,
248254 F47B070E1E9A6E55006711D9 /* StatusBar.swift in Sources */,
255+ F463F6DB1EAA3C9700FAB2E3 /* LimitedArraySerializer.swift in Sources */,
249256 F4D346941EA644170031AFB3 /* LimitedArray.swift in Sources */,
250257 F47B07121EA10A3E006711D9 /* ChooseFolerItem.swift in Sources */,
251258 );
@@ -256,6 +263,7 @@
256263 buildActionMask = 2147483647;
257264 files = (
258265 F4DBE9281EA7864B00CEB984 /* LimitedArrayTest.swift in Sources */,
266+ F463F6D91EAA3B8F00FAB2E3 /* CollectionSerializerTest.swift in Sources */,
259267 F47B06FD1E9A5DF9006711D9 /* GoIntoTests.swift in Sources */,
260268 );
261269 runOnlyForDeploymentPostprocessing = 0;
--- /dev/null
+++ b/GoInto/LimitedArraySerializer.swift
@@ -0,0 +1,50 @@
1+//
2+// LimitedArraySerializer.swift
3+// GoInto
4+//
5+// Created by Hori,Masaki on 2017/04/21.
6+// Copyright © 2017年 Hori,Masaki. All rights reserved.
7+//
8+
9+import Foundation
10+
11+private struct LimitedArrayWrapperCodingKey {
12+ static let array = "LimitedArrayWrapperCodingKey.Array"
13+ static let size = "LimitedArrayWrapperCodingKey.Size"
14+}
15+
16+private class LimitedArrayWrapper<Element: Equatable>: NSObject, NSCoding {
17+ let array: [Element]
18+ let size: Int
19+
20+ init(_ limited: LimitedArray<Element>) {
21+ array = limited.array
22+ size = limited.size
23+ }
24+ required init?(coder aDecoder: NSCoder) {
25+ guard let array = aDecoder.decodeObject(forKey: LimitedArrayWrapperCodingKey.array) as? [Element]
26+ else { return nil }
27+ self.array = array
28+ size = aDecoder.decodeInteger(forKey: LimitedArrayWrapperCodingKey.size)
29+ }
30+ func encode(with aCoder: NSCoder) {
31+ aCoder.encode(array, forKey: LimitedArrayWrapperCodingKey.array)
32+ aCoder.encode(size, forKey: LimitedArrayWrapperCodingKey.size)
33+ }
34+}
35+
36+class LimitedArraySerializer {
37+
38+ class func seirialize<Element>(_ object: LimitedArray<Element>) -> Data {
39+ let wrapper = LimitedArrayWrapper(object)
40+ return NSKeyedArchiver.archivedData(withRootObject: wrapper)
41+ }
42+
43+ class func deserialize<Element>(_ data: Data) -> LimitedArray<Element>? {
44+ guard let wrapper = NSKeyedUnarchiver.unarchiveObject(with: data) as? LimitedArrayWrapper<Element>
45+ else { return nil }
46+ let limited = LimitedArray<Element>(wrapper.size)
47+ wrapper.array.reversed().forEach(limited.append)
48+ return limited
49+ }
50+}
--- /dev/null
+++ b/GoIntoTests/CollectionSerializerTest.swift
@@ -0,0 +1,58 @@
1+//
2+// CollectionSerializerTest.swift
3+// GoInto
4+//
5+// Created by Hori,Masaki on 2017/04/21.
6+// Copyright © 2017年 Hori,Masaki. All rights reserved.
7+//
8+
9+import XCTest
10+
11+@testable import GoInto
12+
13+
14+class CollectionSerializerTest: XCTestCase {
15+
16+ func testExample() {
17+ let limited = LimitedArray<Int>(3)
18+ limited.append(1)
19+ limited.append(2)
20+ limited.append(3)
21+
22+ let data = LimitedArraySerializer.seirialize(limited)
23+ XCTAssertNotNil(data)
24+ let object: LimitedArray<Int> = LimitedArraySerializer.deserialize(data) ?? LimitedArray<Int>(3)
25+
26+ XCTAssertEqual(object.array, limited.array)
27+ XCTAssertEqual(object.size, limited.size)
28+ }
29+
30+ func testURL() {
31+ let limited = LimitedArray<URL>(3)
32+ limited.append(URL(fileURLWithPath: "/System/"))
33+ limited.append(URL(fileURLWithPath: "/Users/"))
34+ limited.append(URL(fileURLWithPath: "/var/"))
35+
36+ let data = LimitedArraySerializer.seirialize(limited)
37+ XCTAssertNotNil(data)
38+ let object: LimitedArray<URL> = LimitedArraySerializer.deserialize(data) ?? LimitedArray<URL>(3)
39+
40+ XCTAssertEqual(object.array, limited.array)
41+ XCTAssertEqual(object.size, limited.size)
42+ }
43+
44+ func testSize() {
45+ let limited = LimitedArray<URL>(5)
46+ limited.append(URL(fileURLWithPath: "/System/"))
47+ limited.append(URL(fileURLWithPath: "/Users/"))
48+ limited.append(URL(fileURLWithPath: "/var/"))
49+
50+ let data = LimitedArraySerializer.seirialize(limited)
51+ XCTAssertNotNil(data)
52+ let object: LimitedArray<URL> = LimitedArraySerializer.deserialize(data) ?? LimitedArray<URL>(5)
53+
54+ XCTAssertEqual(object.array, limited.array)
55+ XCTAssertEqual(object.size, limited.size)
56+ }
57+
58+}