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
store.subscribeState { (state: State) in | |
nameLabel.text = state.name | |
ageLabel.text = "\(state.age)" | |
} |
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
struct State { | |
var name: String | |
var age: Int | |
var nameAndAge: String { | |
// computed-propertyも毎回演算の対象になるので、ReactiveFrameworkのようなcombine-latestもstateとして表現ができます。 | |
return "\(name) \(age)" | |
} | |
} |
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
final class MyViewController: UIViewController { | |
let viewModle: MyViewModel | |
... | |
var cancellable: VergeAnyCancellable? | |
init(viewModel: MyViewModel) { |
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
// ViewModelとして利用したい場合はMyViewModelとしても構いません。 | |
final class MyStore: StoreComponentType { | |
struct State { | |
var name: String = "" | |
var count: Int = 0 | |
} | |
let store: DefaultStore = .init(initialState: .init()) | |
} |
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
struct IncrementAction: ActionType { | |
... | |
} | |
struct DecrementAction: ActionType { | |
... | |
} | |
func reduce(state: State, action: ActionType) -> State { | |
... |
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
enum Action: ActionType { | |
case increment | |
case decrement | |
} | |
func reduce(state: State, action: ActionType) -> State { | |
... | |
} |
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
struct State { | |
var posts: [Post] | |
} | |
struct Author { | |
var username: String | |
var name: String | |
} | |
struct Post { |
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
enum Action { | |
case increment | |
case decrement | |
} |
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
extension Publisher { | |
@discardableResult | |
func start() -> Future<Output, Failure> { | |
return .init { promise in | |
var cancellableRef: Unmanaged<AnyCancellable>? = nil | |
let c = self.sink(receiveCompletion: { (completion) in | |
switch completion { |
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
xcbuild( | |
workspace: ..., | |
scheme: 'Debug', | |
xcargs: '-arch x86_64 -sdk iphonesimulator' | |
) | |
// ハードコードやめられるとベスト | |
path = File.join(Dir.pwd, '../DerivedData/Build/Products/debug-iphonesimulator/MyApp.app') |