Skip to content

Instantly share code, notes, and snippets.

View marty-suzuki's full-sized avatar
Back to the future

Taiki Suzuki marty-suzuki

Back to the future
View GitHub Profile
@marty-suzuki
marty-suzuki / iosMain_GC.kt
Last active October 17, 2021 04:40
An Adapter of Kotlin native GarbageCollector for iOS project
import kotlin.native.internal.GC as internalGC
/**
* https://github.com/JetBrains/kotlin/blob/1.5.30/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/GC.kt
*/
object GC {
var threshold: Int
get() = internalGC.threshold
set(value) { internalGC.threshold = value }
import Combine
import SwiftUI
struct ContentView: View {
@ObservedObject var viewModel = ViewModel()
var body: some View {
Button("Refresh") { viewModel.objectWillChange.send() }
ScrollView(.vertical) {
LazyVStack {
Pod::Spec.new do |spec|
module PrivateRepository
class Spec
attr_reader :version
attr_reader :homepage
attr_reader :source
def initialize(owner, name, version, source)
@version = version
@homepage = "https://github.com/#{owner}/#{name}"
@source = source
enum _Value<Initial, Changed> {
case initial(Initial)
case changed(Changed)
}
typealias StateRepresentable<T> = _Value<T, T>
typealias ChangeHandleable<T> = _Value<Void, T>
extension _Value where Initial == Void {
static func initial() -> _Value<Void, Changed> {
// Playgroundでの実行を想定しているのでCombineを利用
import Combine
// MARK: - CombineをRxSwiftのように定義する
typealias Observable<T> = AnyPublisher<T, Error>
typealias PublishRelay<T> = PassthroughSubject<T, Never>
typealias BehaviorRelay<T> = CurrentValueSubject<T, Never>
typealias DisposeBag = [AnyCancellable]
/// valueのsetterを非公開にしたBehaviorRelay
@marty-suzuki
marty-suzuki / UnioSystem.swift
Last active May 17, 2020 05:51
https://github.com/cats-oss/Unio で公開しているFrameworkの動きを簡易的に表現しています
// Playgroundでの実行を想定しているのでCombineを利用
import Combine
// MARK: - CombineをRxSwiftのように定義する
typealias Observable<T> = AnyPublisher<T, Error>
typealias PublishRelay<T> = PassthroughSubject<T, Never>
typealias BehaviorRelay<T> = CurrentValueSubject<T, Never>
typealias DisposeBag = [AnyCancellable]
// MARK: - Output関連
@startuml
package Reversi.app {
class ViewController {
~ viewModel: ReversiViewModelType
}
}
package ReversiLogic.framework {
class ReversiViewModel {
+ input: InputWrapper<ReversiViewModel.Input>
import Combine
extension Publisher {
func flatMapLatest<T: Publisher>(_ transform: @escaping (Output) -> T) -> Publishers.SwitchToLatest<T, Publishers.Map<Self, T>> where T.Failure == Failure {
map(transform).switchToLatest()
}
}
enum Pattern {
/// - seealso: https://www.hackingwithswift.com/articles/212/whats-new-in-swift-5-2
import Foundation
protocol OptionalType {
associatedtype Wrapped
var value: Wrapped? { get }
}
extension Optional: OptionalType {
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print(Object1().object)
}
}