Skip to content

Commit

Permalink
refactor/#308 메인스레드에서 동작하는 메서드 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
JinUng41 committed Aug 19, 2024
1 parent 1cb08d4 commit 618d917
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions KkuMulKum/Resource/ObservablePattern/ObservablePattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,22 @@ class ObservablePattern<T> {
listener(object, value)
}
}

func bindOnMain(_ listener: @escaping (T) -> Void) {
self.listener = { value in
DispatchQueue.main.async {
listener(value)
}
}
}

func bindOnMain<Object: AnyObject>(with object: Object, _ listener: @escaping (Object, T) -> Void) {
self.listener = { [weak object] value in
guard let object else { return }
DispatchQueue.main.async {
listener(object, value)
}
}
}
}

0 comments on commit 618d917

Please sign in to comment.