mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
create NSSet extension
This commit is contained in:
parent
8c3ad7bec9
commit
43dbcfe27c
7 changed files with 28 additions and 20 deletions
|
|
@ -74,9 +74,7 @@ public final class PDFViewerViewModel: ObservableObject {
|
|||
.sink { [weak self] completion in
|
||||
guard case let .failure(error) = completion else { return }
|
||||
self?.errorMessage = error.localizedDescription
|
||||
} receiveValue: { value in
|
||||
print("highlight value", value)
|
||||
}
|
||||
} receiveValue: { _ in }
|
||||
.store(in: &subscriptions)
|
||||
}
|
||||
|
||||
|
|
@ -100,9 +98,7 @@ public final class PDFViewerViewModel: ObservableObject {
|
|||
.sink { [weak self] completion in
|
||||
guard case let .failure(error) = completion else { return }
|
||||
self?.errorMessage = error.localizedDescription
|
||||
} receiveValue: { value in
|
||||
print("highlight value", value)
|
||||
}
|
||||
} receiveValue: { _ in }
|
||||
.store(in: &subscriptions)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,11 @@ final class LabelsViewModel: ObservableObject {
|
|||
/// - dataService: `DataService` reference
|
||||
/// - item: Optional `FeedItem` for applying labels to a single item
|
||||
/// - initiallySelectedLabels: Optional `[FeedItemLabel]` for filtering a list of items
|
||||
func loadLabels(dataService: DataService, item: FeedItemDep? = nil, initiallySelectedLabels: [FeedItemLabelDep]? = nil) {
|
||||
func loadLabels(
|
||||
dataService: DataService,
|
||||
item: FeedItemDep? = nil,
|
||||
initiallySelectedLabels: [FeedItemLabelDep]? = nil
|
||||
) {
|
||||
guard !hasLoadedInitialLabels else { return }
|
||||
isLoading = true
|
||||
|
||||
|
|
@ -82,7 +86,11 @@ final class LabelsViewModel: ObservableObject {
|
|||
.store(in: &subscriptions)
|
||||
}
|
||||
|
||||
func saveItemLabelChanges(itemID: String, dataService: DataService, onComplete: @escaping ([FeedItemLabelDep]) -> Void) {
|
||||
func saveItemLabelChanges(
|
||||
itemID: String,
|
||||
dataService: DataService,
|
||||
onComplete: @escaping ([FeedItemLabelDep]) -> Void
|
||||
) {
|
||||
isLoading = true
|
||||
dataService.updateArticleLabelsPublisher(itemID: itemID, labelIDs: selectedLabels.map(\.id)).sink(
|
||||
receiveCompletion: { [weak self] _ in
|
||||
|
|
|
|||
|
|
@ -110,13 +110,3 @@ public extension DataService {
|
|||
|
||||
func invalidateCachedPage(slug _: String?) {}
|
||||
}
|
||||
|
||||
// TODO: move to util file
|
||||
extension Optional where Wrapped == NSSet {
|
||||
func asArray<T: Hashable>(of _: T.Type) -> [T] {
|
||||
if let set = self as? Set<T> {
|
||||
return Array(set)
|
||||
}
|
||||
return [T]()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import Models
|
|||
import SwiftGraphQL
|
||||
|
||||
public extension DataService {
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
// swiftlint:disable:next function_parameter_count function_body_length
|
||||
func mergeHighlightPublisher(
|
||||
shortId: String,
|
||||
highlightID: String,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ import Models
|
|||
import SwiftGraphQL
|
||||
|
||||
public extension DataService {
|
||||
func updateArticleLabelsPublisher(itemID: String, labelIDs: [String]) -> AnyPublisher<[FeedItemLabelDep], BasicError> {
|
||||
func updateArticleLabelsPublisher(
|
||||
itemID: String,
|
||||
labelIDs: [String]
|
||||
) -> AnyPublisher<[FeedItemLabelDep], BasicError> {
|
||||
enum MutationResult {
|
||||
case saved(feedItem: [FeedItemLabelDep])
|
||||
case error(errorCode: Enums.SetLabelsErrorCode)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import Models
|
|||
import SwiftGraphQL
|
||||
|
||||
public extension DataService {
|
||||
// swiftlint:disable:next function_body_length
|
||||
func libraryItemsPublisher(
|
||||
limit: Int,
|
||||
sortDescending: Bool,
|
||||
|
|
|
|||
10
apple/OmnivoreKit/Sources/Utils/NSSetExtension.swift
Normal file
10
apple/OmnivoreKit/Sources/Utils/NSSetExtension.swift
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import Foundation
|
||||
|
||||
public extension Optional where Wrapped == NSSet {
|
||||
func asArray<T: Hashable>(of _: T.Type) -> [T] {
|
||||
if let set = self as? Set<T> {
|
||||
return Array(set)
|
||||
}
|
||||
return [T]()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue