Skip to content

Commit

Permalink
Swiftformat
Browse files Browse the repository at this point in the history
  • Loading branch information
nickromano committed Apr 27, 2023
1 parent dd7a41e commit 1f7d18c
Show file tree
Hide file tree
Showing 21 changed files with 676 additions and 679 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.8
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--indent 2
38 changes: 19 additions & 19 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
import PackageDescription

let package = Package(
name: "WatchSync",
platforms: [
.iOS(.v13),
.watchOS(.v4),
],
products: [
.library(name: "WatchSync", targets: ["WatchSync"]),
],
dependencies: [
.package(url: "https://github.com/1024jp/GzipSwift", from: "5.0.0"),
],
targets: [
.target(
name: "WatchSync",
dependencies: [
.product(name: "Gzip", package: "GzipSwift"),
]
),
]
name: "WatchSync",
platforms: [
.iOS(.v13),
.watchOS(.v4),
],
products: [
.library(name: "WatchSync", targets: ["WatchSync"]),
],
dependencies: [
.package(url: "https://github.com/1024jp/GzipSwift", from: "5.0.0"),
],
targets: [
.target(
name: "WatchSync",
dependencies: [
.product(name: "Gzip", package: "GzipSwift"),
]
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ import WatchKit
import WatchSync

class ExtensionDelegate: NSObject, WKExtensionDelegate {
var subscriptionToken: SubscriptionToken?

var subscriptionToken: SubscriptionToken?

func applicationDidFinishLaunching() {

WatchSync.shared.activateSession { error in
if let error = error {
print("Error activating session \(error.localizedDescription)")
return
}
print("Activated")
}
func applicationDidFinishLaunching() {
WatchSync.shared.activateSession { error in
if let error = error {
print("Error activating session \(error.localizedDescription)")
return
}
print("Activated")
}

subscriptionToken = WatchSync.shared.subscribeToMessages(ofType: MyMessage.self) { myMessage in
print(myMessage)
}
subscriptionToken = WatchSync.shared.subscribeToMessages(ofType: MyMessage.self) { myMessage in
print(myMessage)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,39 @@
// Copyright © 2018 Ten Minute Wait. All rights reserved.
//

import WatchKit
import Foundation
import WatchKit

import WatchSync

class InterfaceController: WKInterfaceController {
var subscriptionToken: SubscriptionToken?

var subscriptionToken: SubscriptionToken?

@IBOutlet var receivedLabel: WKInterfaceLabel!
@IBOutlet var receivedLabel: WKInterfaceLabel!

override func awake(withContext context: Any?) {
super.awake(withContext: context)
override func awake(withContext context: Any?) {
super.awake(withContext: context)

receivedLabel.setHidden(true)
receivedLabel.setHidden(true)

subscriptionToken = WatchSync.shared.subscribeToMessages(ofType: MyMessage.self) { [weak self] myMessage in
self?.receivedLabel.setHidden(false)
subscriptionToken = WatchSync.shared.subscribeToMessages(ofType: MyMessage.self) { [weak self] myMessage in
self?.receivedLabel.setHidden(false)

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: {
self?.receivedLabel.setHidden(true)
})
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
self?.receivedLabel.setHidden(true)
}

print(String(describing: myMessage.myString), String(describing: myMessage.myDate))
}
print(String(describing: myMessage.myString), String(describing: myMessage.myDate))
}
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,29 @@
// Copyright © 2018 Ten Minute Wait. All rights reserved.
//

import WatchKit
import Foundation
import UserNotifications
import WatchKit

class NotificationController: WKUserNotificationInterfaceController {
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

/*
override func didReceive(_ notification: UNNotification, withCompletion completionHandler: @escaping (WKUserNotificationInterfaceType) -> Swift.Void) {
// This method is called when a notification needs to be presented.
// Implement it if you use a dynamic notification interface.
// Populate your dynamic notification interface as quickly as possible.
//
// After populating your dynamic notification interface call the completion block.
completionHandler(.custom)
}
*/
/*
override func didReceive(_ notification: UNNotification, withCompletion completionHandler: @escaping (WKUserNotificationInterfaceType) -> Swift.Void) {
// This method is called when a notification needs to be presented.
// Implement it if you use a dynamic notification interface.
// Populate your dynamic notification interface as quickly as possible.
//
// After populating your dynamic notification interface call the completion block.
completionHandler(.custom)
}
*/
}
24 changes: 11 additions & 13 deletions Sources/WatchSync Example/WatchSync Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ import WatchSync

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

WatchSync.shared.activateSession { error in
if let error = error {
print("Error activating session \(error.localizedDescription)")
return
}
print("Activated")
}

return true
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
WatchSync.shared.activateSession { error in
if let error = error {
print("Error activating session \(error.localizedDescription)")
return
}
print("Activated")
}

return true
}
}
4 changes: 2 additions & 2 deletions Sources/WatchSync Example/WatchSync Example/MyMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ import WatchSync
Example message
*/
struct MyMessage: SyncableMessage {
var myString: String?
var myDate: Date?
var myString: String?
var myDate: Date?
}
81 changes: 40 additions & 41 deletions Sources/WatchSync Example/WatchSync Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,51 @@ import UIKit
import WatchSync

class ViewController: UIViewController {
var subscriptionToken: SubscriptionToken?

var subscriptionToken: SubscriptionToken?
override func viewDidLoad() {
super.viewDidLoad()

override func viewDidLoad() {
super.viewDidLoad()

subscriptionToken = WatchSync.shared.subscribeToMessages(ofType: MyMessage.self) { myMessage in
print(String(describing: myMessage.myString), String(describing: myMessage.myDate))
}
subscriptionToken = WatchSync.shared.subscribeToMessages(ofType: MyMessage.self) { myMessage in
print(String(describing: myMessage.myString), String(describing: myMessage.myDate))
}
}

@IBAction func sendMessageButtonPressed(_ sender: Any) {
let myMessage = MyMessage(myString: "Test", myDate: Date())
@IBAction func sendMessageButtonPressed(_: Any) {
let myMessage = MyMessage(myString: "Test", myDate: Date())

WatchSync.shared.sendMessage(myMessage) { result in
switch result {
case .failure(let failure):
switch failure {
case .sessionNotActivated:
break
case .watchConnectivityNotAvailable:
break
case .unableToSerializeMessageAsJSON(let error), .unableToCompressMessage(let error):
print(error.localizedDescription)
case .watchAppNotPaired:
break
case .watchAppNotInstalled:
break
case .unhandledError(let error):
print(error.localizedDescription)
case .badPayloadError(let error):
print(error.localizedDescription)
case .failedToDeliver(let error):
let alertController = UIAlertController(title: "", message: "Failed to Deliver \(error.localizedDescription)", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
case .sent:
let alertController = UIAlertController(title: "", message: "Sent!", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
case .delivered:
let alertController = UIAlertController(title: "", message: "Delivery Confirmed", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
WatchSync.shared.sendMessage(myMessage) { result in
switch result {
case let .failure(failure):
switch failure {
case .sessionNotActivated:
break
case .watchConnectivityNotAvailable:
break
case let .unableToSerializeMessageAsJSON(error), let .unableToCompressMessage(error):
print(error.localizedDescription)
case .watchAppNotPaired:
break
case .watchAppNotInstalled:
break
case let .unhandledError(error):
print(error.localizedDescription)
case let .badPayloadError(error):
print(error.localizedDescription)
case let .failedToDeliver(error):
let alertController = UIAlertController(title: "", message: "Failed to Deliver \(error.localizedDescription)", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
case .sent:
let alertController = UIAlertController(title: "", message: "Sent!", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
case .delivered:
let alertController = UIAlertController(title: "", message: "Delivery Confirmed", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
// Copyright © 2018 Ten Minute Wait. All rights reserved.
//

import XCTest
@testable import WatchSync_Example
import XCTest

class WatchSyncExampleTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
func testPerformanceExample() {
// This is an example of a performance test case.
measure {
// Put the code you want to measure the time of here.
}
}
}
Loading

0 comments on commit 1f7d18c

Please sign in to comment.