Skip to content

Commit

Permalink
Replace unowned vars with regular vars to avoid crashes (#1554)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbugli authored and nuno-vieira committed Oct 21, 2021
1 parent d7db658 commit 3ae8327
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ final class ConnectionRecoveryUpdater_Tests: XCTestCase {

AssertAsync {
Assert.canBeReleased(&updater)
Assert.canBeReleased(&database)
Assert.canBeReleased(&webSocketClient)
Assert.canBeReleased(&apiClient)
}

super.tearDown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ final class DatabaseCleanupUpdater_Tests: XCTestCase {

AssertAsync {
Assert.canBeReleased(&databaseCleanupUpdater)
Assert.canBeReleased(&database)
Assert.canBeReleased(&webSocketClient)
Assert.canBeReleased(&apiClient)
}

super.tearDown()
Expand Down
1 change: 0 additions & 1 deletion Sources/StreamChat/Workers/TypingEventSender_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class TypingEventsSender_Tests: XCTestCase {

override func tearDown() {
apiClient.cleanUp()
AssertAsync.canBeReleased(&database)
super.tearDown()
}

Expand Down
18 changes: 8 additions & 10 deletions Sources/StreamChat/Workers/Worker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ typealias EventWorkerBuilder = (
_ apiClient: APIClient
) -> Worker

// This is a super-class instead of protocol because we need to be sure, `unowned` is used for socket client and api client
class Worker: NSObject { // TODO: remove NSObject
unowned let database: DatabaseContainer
unowned let apiClient: APIClient

init(database: DatabaseContainer, apiClient: APIClient) {
class Worker {
let database: DatabaseContainer
let apiClient: APIClient

public init(database: DatabaseContainer, apiClient: APIClient) {
self.database = database
self.apiClient = apiClient
super.init()
}
}

class EventWorker: Worker {
unowned let eventNotificationCenter: EventNotificationCenter
init(
let eventNotificationCenter: EventNotificationCenter

public init(
database: DatabaseContainer,
eventNotificationCenter: EventNotificationCenter,
apiClient: APIClient
Expand Down

0 comments on commit 3ae8327

Please sign in to comment.