Skip to content

Commit

Permalink
fix: reformat and add deinit print
Browse files Browse the repository at this point in the history
  • Loading branch information
gtokman committed May 8, 2021
1 parent c8ce92e commit 4e0a09a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 11 additions & 2 deletions Sources/ExtensionKit/CoreLocation/AuthorizationPublisher.swift
Expand Up @@ -14,8 +14,7 @@ protocol SubscriptionAuthorizationDelegate: class {
final class AuthorizationSubscription <S: Subscriber>: NSObject,
PublisherAuthorizationDelegate,
Subscription where S.Input == CLAuthorizationStatus,
S.Failure == Never {

S.Failure == Never {
typealias Output = CLAuthorizationStatus
typealias Failure = Never

Expand All @@ -32,6 +31,10 @@ final class AuthorizationSubscription <S: Subscriber>: NSObject,
self.delegate = delegate
self.authorizationType = authorizationType
}

deinit {
printDeinitMessage()
}

func request(_ demand: Subscribers.Demand) {
delegate?.requestAuthorization(type: authorizationType)
Expand All @@ -42,6 +45,8 @@ final class AuthorizationSubscription <S: Subscriber>: NSObject,
delegate = nil
}

// MARK: - PublisherAuthorizationDelegate

func send(status: CLAuthorizationStatus) {
_ = subscriber?.receive(status)
}
Expand All @@ -65,6 +70,10 @@ final class AuthorizationPublisher: NSObject,
super.init()
self.manager.delegate = self
}

deinit {
printDeinitMessage()
}

func receive<S>(subscriber: S) where S: Subscriber, AuthorizationPublisher.Failure == S.Failure, AuthorizationPublisher.Output == S.Input {
let subscription = AuthorizationSubscription(
Expand Down
14 changes: 11 additions & 3 deletions Sources/ExtensionKit/CoreLocation/LocationPublisher.swift
Expand Up @@ -36,6 +36,10 @@ final class LocationSubscription <S: Subscriber>:
publisherDelegate?.startLocationUpdates()
}

deinit {
printDeinitMessage()
}

func cancel() {
subscriber = nil
publisherDelegate = nil
Expand All @@ -51,16 +55,20 @@ final class LocationPublisher: NSObject,
typealias Failure = Error

private let manager: CLLocationManager
private let onTimeUpdate: Bool
private let oneTimeUpdate: Bool
private var subscriberDelegate: SubscriptionLocationDelegate?

init(manager: CLLocationManager, onTimeUpdate: Bool = false) {
self.manager = manager
self.onTimeUpdate = onTimeUpdate
self.oneTimeUpdate = onTimeUpdate
super.init()
self.manager.delegate = self
}

deinit {
printDeinitMessage()
}

// MARK: Publisher

func receive<S>(subscriber: S) where S : Subscriber, LocationPublisher.Failure == S.Failure, LocationPublisher.Output == S.Input {
Expand All @@ -86,7 +94,7 @@ final class LocationPublisher: NSObject,
// MARK: PublisherLocationDelegate

func startLocationUpdates() {
if onTimeUpdate {
if oneTimeUpdate {
manager.requestLocation()
} else {
manager.startUpdatingLocation()
Expand Down

0 comments on commit 4e0a09a

Please sign in to comment.