Skip to content

Commit 0ae493c

Browse files
author
Vance Will
committed
format
1 parent 165e1ee commit 0ae493c

11 files changed

+252
-95
lines changed

Package.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ let package = Package(
88
platforms: [
99
.iOS(.v10),
1010
.macOS(.v10_10),
11-
.watchOS(.v4)
11+
.watchOS(.v4),
1212
],
1313
products: [
1414
.library(
1515
name: "Wormhole",
16-
targets: ["Wormhole"]),
16+
targets: ["Wormhole"]
17+
),
1718
],
1819
dependencies: [
1920
.package(
20-
url: "https://github.com/Flight-School/AnyCodable",
21-
from: "0.4.0"
22-
)
21+
url: "https://github.com/Flight-School/AnyCodable",
22+
from: "0.4.0"
23+
),
2324
],
2425
targets: [
2526
.target(
2627
name: "Wormhole",
2728
dependencies: ["AnyCodable"],
28-
path: "Sources")
29+
path: "Sources"
30+
),
2931
]
3032
)

Sources/Wormhole/CoordinatedFileTransiting.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1+
// CoordinatedFileTransiting.swift
2+
// Copyright (c) 2014 Mutual Mobile (http://www.mutualmobile.com/)
3+
// Created by Vance Will (vancewilll@icloud.com).
14
//
2-
// CoordinatedFileTransiting.swift
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
311
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
414
//
5-
// Created by Ethan Mengoreo on 2021/2/3.
6-
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
722

8-
import Foundation
923
import AnyCodable
24+
import Foundation
1025

1126
/// This class inherits from the default implementation of the MMWormholeTransiting protocol and implements message transiting in a similar way but using NSFileCoordinator for its file reading and writing.
1227
public class CoordinatedFileTransiting: FileTransiting {
13-
1428
/// The default file writing option is `Data.WritingOptions.atomic`. It may be important for your app to use
1529
/// additional file writing options to control the specific data protection class for message files
1630
/// being written by your application. When you create your file transiting object, set this property
1731
/// to the additional writing options you want to use.
1832
public var additionalDataWritingOptions = Data.WritingOptions.atomic
1933

20-
public override func writeMessage<T: Codable>(_ message: T?, for identifier: String) -> Bool {
34+
override public func writeMessage<T: Codable>(_ message: T?, for identifier: String) -> Bool {
2135
guard let message = message else {
2236
// just notification
2337
return true
@@ -48,7 +62,7 @@ public class CoordinatedFileTransiting: FileTransiting {
4862
return (error == nil) && succeeded
4963
}
5064

51-
public override func message(for identifier: String) -> Any? {
65+
override public func message(for identifier: String) -> Any? {
5266
guard let fileURL = fileDirectory(for: identifier) else {
5367
return nil
5468
}

Sources/Wormhole/FileTransiting.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
// FileTransiting.swift
2+
// Copyright (c) 2014 Mutual Mobile (http://www.mutualmobile.com/)
3+
// Created by Vance Will (vancewilll@icloud.com).
14
//
2-
// FileTransiting.swift
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
311
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
414
//
5-
// Created by Ethan Mengoreo on 2021/2/3.
6-
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
722

8-
import Foundation
923
import AnyCodable
24+
import Foundation
1025

1126
/// This class is a default implementation of the `Wormhole.Transiting` protocol that implements
1227
/// message transiting by archiving and unarchiving messages that are written and read to files on
@@ -121,8 +136,7 @@ public class FileTransiting: Transiting {
121136
try? fileManager.contentsOfDirectory(atPath: directory.path)
122137
.forEach(fileManager.removeItem)
123138
}
124-
125-
139+
126140
/// This method returns the full file directory for the file associated with the given message identifier.
127141
/// It includes the optional container passed in the designated initializer if there is one.
128142
/// Subclasses can use this method to provide custom implementations.

Sources/Wormhole/Helpers.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
// Helpers.swift
2+
// Copyright (c) 2014 Mutual Mobile (http://www.mutualmobile.com/)
3+
// Created by Vance Will (vancewilll@icloud.com).
14
//
2-
// Helpers.swift
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
311
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
414
//
5-
// Created by Ethan Mengoreo on 2021/2/3.
6-
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
722

8-
import Foundation
923
import CoreServices
24+
import Foundation
1025

1126
extension Notification.Name {
1227
static let wormhole = Notification.Name("wormhole.Z3SdZWgvUO5T8rYmnW8d")
@@ -16,7 +31,6 @@ func bridge<T: AnyObject>(obj: T) -> UnsafeRawPointer {
1631
return UnsafeRawPointer(Unmanaged.passUnretained(obj).toOpaque())
1732
}
1833

19-
2034
let darwinNotiCallback: @convention(c) (
2135
_ center: CFNotificationCenter?,
2236
_ observer: UnsafeMutableRawPointer?,

Sources/Wormhole/Session.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
// Session.swift
2+
// Copyright (c) 2014 Mutual Mobile (http://www.mutualmobile.com/)
3+
// Created by Vance Will (vancewilll@icloud.com).
14
//
2-
// Session.swift
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
311
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
414
//
5-
// Created by Ethan Mengoreo on 2021/2/3.
6-
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
722

823
#if !os(macOS)
24+
import AnyCodable
925
import Foundation
1026
import WatchConnectivity
11-
import AnyCodable
1227

1328
public class Session: Wormhole {
1429
/// This is a specific instance of `Wormhole.Session` that should be used for listening. You
@@ -59,6 +74,7 @@ import AnyCodable
5974
}
6075

6176
// MARK: Private subclass methods
77+
6278
override func registerNotification(with _: String) {
6379
// Wormhole.Session uses WatchConnectivity delegate callbacks and does not support Darwin Notification Center notifications.
6480
}
@@ -103,22 +119,22 @@ import AnyCodable
103119
else {
104120
return
105121
}
106-
122+
107123
guard let data = try? Data(contentsOf: file.fileURL) else {
108124
notifyListener(with: nil, for: identifier)
109125
return
110126
}
111127
let msgContainer = try? JSONDecoder().decode(AnyCodable.self, from: data)
112128
notifyListener(with: msgContainer?.value, for: identifier)
113-
129+
114130
// update file
115131
guard
116132
let fileMessenger = messenger as? FileTransiting,
117133
let directory = fileMessenger.fileDirectory(for: identifier)
118134
else {
119135
return
120136
}
121-
137+
122138
try? data.write(to: directory)
123139
}
124140
}

Sources/Wormhole/SessionContextTransiting.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
// SessionContextTransiting.swift
2+
// Copyright (c) 2014 Mutual Mobile (http://www.mutualmobile.com/)
3+
// Created by Vance Will (vancewilll@icloud.com).
14
//
2-
// SessionContextTransiting.swift
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
311
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
414
//
5-
// Created by Ethan Mengoreo on 2021/2/3.
6-
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
722

823
#if !os(macOS)
24+
import AnyCodable
925
import Foundation
1026
import WatchConnectivity
11-
import AnyCodable
1227

1328
/// This class provides support for the WatchConnectivity framework's Application Context message
1429
/// reading and writing ability. This class will pass it's messages directly via the

Sources/Wormhole/SessionFileTransiting.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
// SessionFileTransiting.swift
2+
// Copyright (c) 2014 Mutual Mobile (http://www.mutualmobile.com/)
3+
// Created by Vance Will (vancewilll@icloud.com).
14
//
2-
// SessionFileTransiting.swift
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
311
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
414
//
5-
// Created by Ethan Mengoreo on 2021/2/3.
6-
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
722

823
#if !os(macOS)
24+
import AnyCodable
925
import Foundation
1026
import WatchConnectivity
11-
import AnyCodable
1227

1328
/// This class provides support for the WatchConnectivity framework's file transfer ability. This class
1429
/// will behave very similar to the `Wormhole.FileTransiting` implementation, meaning it will archive

0 commit comments

Comments
 (0)