Skip to content

Instantly share code, notes, and snippets.

View muukii's full-sized avatar
✈️
We live in a twilight world.

Hiroshi Kimura muukii

✈️
We live in a twilight world.
View GitHub Profile
store.subscribeState { (state: State) in
nameLabel.text = state.name
ageLabel.text = "\(state.age)"
}
@muukii
muukii / State.swift
Last active November 11, 2020 06:59
struct State {
var name: String
var age: Int
var nameAndAge: String {
// computed-propertyも毎回演算の対象になるので、ReactiveFrameworkのようなcombine-latestもstateとして表現ができます。
return "\(name) \(age)"
}
}
final class MyViewController: UIViewController {
let viewModle: MyViewModel
...
var cancellable: VergeAnyCancellable?
init(viewModel: MyViewModel) {
// ViewModelとして利用したい場合はMyViewModelとしても構いません。
final class MyStore: StoreComponentType {
struct State {
var name: String = ""
var count: Int = 0
}
let store: DefaultStore = .init(initialState: .init())
}
struct IncrementAction: ActionType {
...
}
struct DecrementAction: ActionType {
...
}
func reduce(state: State, action: ActionType) -> State {
...
enum Action: ActionType {
case increment
case decrement
}
func reduce(state: State, action: ActionType) -> State {
...
}
struct State {
var posts: [Post]
}
struct Author {
var username: String
var name: String
}
struct Post {
enum Action {
case increment
case decrement
}
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 {
xcbuild(
workspace: ...,
scheme: 'Debug',
xcargs: '-arch x86_64 -sdk iphonesimulator'
)
// ハードコードやめられるとベスト
path = File.join(Dir.pwd, '../DerivedData/Build/Products/debug-iphonesimulator/MyApp.app')