Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update filter preservation to use Codable compatible serialization to…
… faciliate removing SwiftyJSON
- Loading branch information
1 parent
1da792a
commit e5862ee
Showing
11 changed files
with
133 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
github "SwiftyJSON/SwiftyJSON" ~> 5.0 | ||
|
||
github "ReactiveX/RxSwift" ~> 5.0 | ||
|
||
github "realm/realm-cocoa" ~> 4.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// FilterState.swift | ||
// WWDC | ||
// | ||
// Created by Allen Humphreys on 7/13/20. | ||
// Copyright © 2020 Guilherme Rambo. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct WWDCFiltersState: Codable { | ||
let scheduleTab, videosTab: WWDCFiltersState.Tab | ||
|
||
enum CodingKeys: String, CodingKey { | ||
// Key names are for backward compatibility with the old way of serializing the state | ||
case scheduleTab = "WWDC.MainWindowTab.schedule" | ||
case videosTab = "WWDC.MainWindowTab.videos" | ||
} | ||
} | ||
|
||
extension WWDCFiltersState { | ||
struct Tab: Codable { | ||
let focus, event, track: MultipleChoiceFilter.State? | ||
let isDownloaded, isFavorite, hasBookmarks, isUnwatched: ToggleFilter.State? | ||
let text: TextualFilter.State? | ||
} | ||
} | ||
|
||
extension WWDCFiltersState.Tab { | ||
init(filters: [FilterType]) { | ||
self = .init( | ||
focus: filters.get(MultipleChoiceFilter.self, for: .focus)?.state, | ||
event: filters.get(MultipleChoiceFilter.self, for: .event)?.state, | ||
track: filters.get(MultipleChoiceFilter.self, for: .track)?.state, | ||
isDownloaded: filters.get(ToggleFilter.self, for: .isDownloaded)?.state, | ||
isFavorite: filters.get(ToggleFilter.self, for: .isFavorite)?.state, | ||
hasBookmarks: filters.get(ToggleFilter.self, for: .hasBookmarks)?.state, | ||
isUnwatched: filters.get(ToggleFilter.self, for: .isUnwatched)?.state, | ||
text: filters.get(TextualFilter.self, for: .text)?.state | ||
) | ||
} | ||
} | ||
|
||
extension Array where Element == FilterType { | ||
func get<T: FilterType>(_ type: T.Type, for identifier: FilterIdentifier) -> T? { | ||
let result = self.first { (filter) -> Bool in | ||
return filter.identifier == identifier && filter is T | ||
} | ||
|
||
return result as? T | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.