Skip to content

Commit

Permalink
Essential changes for Xcode 11 beta4
Browse files Browse the repository at this point in the history
  • Loading branch information
johnno1962 committed Jul 28, 2019
1 parent 5722939 commit e3a4b91
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Other Projects/2048 Game/SwiftUI2048/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
gameLogic.newGame()
}

override func buildCommands(with builder: UICommandBuilder) {
override func buildMenu(with builder: UIMenuBuilder) {
builder.remove(menu: .edit)
builder.remove(menu: .format)
builder.remove(menu: .view)

builder.replaceChildren(ofMenu: .file) { oldChildren in
var newChildren = oldChildren
let newGameItem = UIMutableKeyCommand(input: "N",
let newGameItem = UIKeyCommand(input: "N",
modifierFlags: .command,
action: #selector(newGame(_:)))
newGameItem.title = "New Game"
Expand Down
8 changes: 4 additions & 4 deletions Other Projects/2048 Game/SwiftUI2048/Models/GameLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class GameLogic : BindableObject {

typealias BlockMatrixType = BlockMatrix<IdentifiedBlock>

let didChange = PassthroughSubject<GameLogic, Never>()
let willChange = PassthroughSubject<GameLogic, Never>()

fileprivate var _blockMatrix: BlockMatrixType!
var blockMatrix: BlockMatrixType {
Expand All @@ -42,12 +42,12 @@ final class GameLogic : BindableObject {
_blockMatrix = BlockMatrixType()
generateNewBlocks()

didChange.send(self)
willChange.send(self)
}

func move(_ direction: Direction) {
defer {
didChange.send(self)
willChange.send(self)
}

var moved = false
Expand Down Expand Up @@ -136,7 +136,7 @@ final class GameLogic : BindableObject {

// Don't forget to sync data.
defer {
didChange.send(self)
willChange.send(self)
}

// Place the first block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct HikeView: View {
var transition: AnyTransition {
let insertion = AnyTransition.move(edge: .trailing)
.combined(with: .opacity)
let removal = AnyTransition.scale()
let removal = AnyTransition.scale(scale: 0.0)
.combined(with: .opacity)
return .asymmetric(insertion: insertion, removal: removal)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import Combine
import SwiftUI

final class UserData: BindableObject {
let didChange = PassthroughSubject<UserData, Never>()
let willChange = PassthroughSubject<UserData, Never>()

var showFavoritesOnly = false {
didSet {
didChange.send(self)
willChange.send(self)
}
}

var landmarks = landmarkData {
didSet {
didChange.send(self)
willChange.send(self)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension Publisher {
extension Publisher {

static func empty() -> AnyPublisher<Output, Failure> {
return Publishers.Empty()
return Empty()
.eraseToAnyPublisher()
}

Expand All @@ -51,7 +51,7 @@ extension Publisher {
}

static func fail(_ error: Failure) -> AnyPublisher<Output, Failure> {
return Publishers.Fail(error: error)
return Fail(error: error)
.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import SwiftUI
import Combine

final class SearchUserViewModel: BindableObject {
var didChange = PassthroughSubject<SearchUserViewModel, Never>()
var willChange = PassthroughSubject<SearchUserViewModel, Never>()

private(set) var users = [User]() {
didSet {
didChange.send(self)
willChange.send(self)
}
}

private(set) var userImages = [User: UIImage]() {
didSet {
didChange.send(self)
willChange.send(self)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct HikeView: View {
var transition: AnyTransition {
let insertion = AnyTransition.move(edge: .trailing)
.combined(with: .opacity)
let removal = AnyTransition.scale()
let removal = AnyTransition.scale(scale: 0.0)
.combined(with: .opacity)
return .asymmetric(insertion: insertion, removal: removal)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import Combine
import SwiftUI

final class UserData: BindableObject {
let didChange = PassthroughSubject<UserData, Never>()
let willChange = PassthroughSubject<UserData, Never>()

var showFavoritesOnly = false {
didSet {
didChange.send(self)
willChange.send(self)
}
}

var landmarks = landmarkData {
didSet {
didChange.send(self)
willChange.send(self)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ struct UserDefaultValue<Value: Codable> {
}

final class UserData: BindableObject {
let didChange = PassthroughSubject<UserData, Never>()
let willChange = PassthroughSubject<UserData, Never>()

@UserDefaultValue(key: "allCurrencies", defaultValue: defaultCurrencies)
var allCurrencies: [Currency] {
didSet {
didChange.send(self)
willChange.send(self)
}
}

@UserDefaultValue(key: "baseCurrency", defaultValue: defaultCurrencies[0])
var baseCurrency: Currency {
didSet {
didChange.send(self)
willChange.send(self)
}
}

@UserDefaultValue(key: "userCurrency", defaultValue: defaultCurrencies)
var userCurrency: [Currency] {
didSet {
didChange.send(self)
willChange.send(self)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import Combine
import SwiftUI

final class UserData: BindableObject {
let didChange = PassthroughSubject<UserData, Never>()
let willChange = PassthroughSubject<UserData, Never>()

var showFavoritesOnly = false {
didSet {
didChange.send(self)
willChange.send(self)
}
}

var landmarks = landmarkData {
didSet {
didChange.send(self)
willChange.send(self)
}
}
}
4 changes: 2 additions & 2 deletions Other Projects/Example To-Do App/SwiftUITodo/UserData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ private let defaultTasks: [Task] = [
]

final class UserData: BindableObject {
let didChange = PassthroughSubject<UserData, Never>()
let willChange = PassthroughSubject<UserData, Never>()

@UserDefaultValue(key: "Tasks", defaultValue: defaultTasks)
var tasks: [Task] {
didSet {
didChange.send(self)
willChange.send(self)
}
}
}
4 changes: 2 additions & 2 deletions Other Projects/Flux/SwiftUI-Flux/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Combine
final class Store<State, Action>: BindableObject {
typealias Reducer = (State, Action) -> State

let didChange = PassthroughSubject<State, Never>()
let willChange = PassthroughSubject<State, Never>()

var state: State {
lock.lock()
Expand All @@ -29,6 +29,6 @@ final class Store<State, Action>: BindableObject {

lock.unlock()

didChange.send(newState)
willChange.send(newState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension Publisher {
extension Publisher {

static func empty() -> AnyPublisher<Output, Failure> {
return Publishers.Empty()
return Empty()
.eraseToAnyPublisher()
}

Expand All @@ -30,7 +30,7 @@ extension Publisher {
}

static func fail(_ error: Failure) -> AnyPublisher<Output, Failure> {
return Publishers.Fail(error: error)
return Fail(error: error)
.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SwiftUI
final class RepositoryListViewModel: BindableObject {
typealias SearchRepositories = (String) -> AnyPublisher<Result<[Repository], ErrorResponse>, Never>

let didChange: AnyPublisher<RepositoryListViewModel, Never>
let willChange: AnyPublisher<RepositoryListViewModel, Never>
private let _didChange = PassthroughSubject<RepositoryListViewModel, Never>()

private let _searchWithQuery = PassthroughSubject<String, Never>()
Expand All @@ -34,7 +34,7 @@ final class RepositoryListViewModel: BindableObject {
init<S: Scheduler>(searchRepositories: @escaping SearchRepositories = RepositoryAPI.search,
mainScheduler: S) {

self.didChange = _didChange.eraseToAnyPublisher()
self.willChange = _didChange.eraseToAnyPublisher()

let response = _searchWithQuery
.filter { !$0.isEmpty }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import Combine
import SwiftUI

final class UserData: BindableObject {
let didChange = PassthroughSubject<UserData, Never>()
let willChange = PassthroughSubject<UserData, Never>()

var showFavoritesOnly = false {
didSet {
didChange.send(self)
willChange.send(self)
}
}

var landmarks = landmarkData {
didSet {
didChange.send(self)
willChange.send(self)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct HikeView: View {
var transition: AnyTransition {
let insertion = AnyTransition.move(edge: .trailing)
.combined(with: .opacity)
let removal = AnyTransition.scale()
let removal = AnyTransition.scale(scale: 0.0)
.combined(with: .opacity)
return .asymmetric(insertion: insertion, removal: removal)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import Combine
import SwiftUI

final class UserData: BindableObject {
let didChange = PassthroughSubject<UserData, Never>()
let willChange = PassthroughSubject<UserData, Never>()

var showFavoritesOnly = false {
didSet {
didChange.send(self)
willChange.send(self)
}
}

var landmarks = landmarkData {
didSet {
didChange.send(self)
willChange.send(self)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
import Combine

final class AppState: BindableObject {
var didChange = PassthroughSubject<AppState, Never>()
var willChange = PassthroughSubject<AppState, Never>()

var moviesState: MoviesState

Expand All @@ -22,7 +22,7 @@ final class AppState: BindableObject {
func dispatch(action: Action) {
moviesState = MoviesStateReducer().reduce(state: moviesState, action: action)
DispatchQueue.main.async {
self.didChange.send(self)
self.willChange.send(self)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
import Combine

final class AppState: BindableObject {
var didChange = PassthroughSubject<AppState, Never>()
var willChange = PassthroughSubject<AppState, Never>()

var usersState: UsersState

Expand All @@ -21,7 +21,7 @@ final class AppState: BindableObject {

func dispatch(action: Action) {
usersState = UserStateReducer().reduce(state: usersState, action: action)
didChange.send(self)
willChange.send(self)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public final class Store<StateType>: BindableObject where StateType: StateMachin
private let initialState: StateType
private var subsequentStates: [StateType] = []

public let didChange = PassthroughSubject<Void, Never>()
public let willChange = PassthroughSubject<Void, Never>()

public init(state: StateType) {
initialState = state
Expand All @@ -23,7 +23,7 @@ public final class Store<StateType>: BindableObject where StateType: StateMachin
var currentStateIndex: Int = 0 {
didSet {
withAnimation {
didChange.send(())
willChange.send(())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Other Projects/UINote/SwiftUINote/Models/UserData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import SwiftUI
import Combine

final class UserData: BindableObject {
let didChange = PassthroughSubject<UserData, Never>()
let willChange = PassthroughSubject<UserData, Never>()

var notes = NoteData.shared.notes {
didSet {
didChange.send(self)
willChange.send(self)
NoteData.shared.notes = notes
}
}
Expand Down
Loading

0 comments on commit e3a4b91

Please sign in to comment.