Skip to content

Instantly share code, notes, and snippets.

View yimajo's full-sized avatar
:octocat:

Yoshinori Imajo yimajo

:octocat:
  • Curiosity Software inc.
  • Tokyo, Japan
  • 11:27 (UTC +09:00)
View GitHub Profile
@yimajo
yimajo / EnvironmentValues+AccessToken.swift
Created August 4, 2020 10:45
An idea to add an AccessToken to EnvironmentValues in the SwiftUI.
import SwiftUI
extension EnvironmentValues {
struct AccessTokenKey: EnvironmentKey {
static var defaultValue: String? {
nil
}
}
var accessToken: String? {
@yimajo
yimajo / combine_glitch.swift
Created May 17, 2020 10:29
Xcode11.4.1のCombineでCombineLatestする際に一つのpublisherを使うとグリッチの出し方がえぐい
//: Playground
import Combine
let publisherA = (1...4).publisher
let publisherB = publisherA.map { $0 * 100 }
_ = Publishers.CombineLatest(publisherA, publisherB)
.print()
.sink(receiveValue: {
@yimajo
yimajo / main.yml
Created April 1, 2020 11:44
GitHub Actionsでtextlintを実行するだけならこれで良さそう
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
textlint:
@yimajo
yimajo / usecase_sample.swift
Created February 17, 2020 05:02
Swift5.2のcallAsFunctionを使ってUseCaseの必須なメソッドとしてみる
import Foundation
protocol UseCase where Failure: Error {
associatedtype Parameters
associatedtype Success
associatedtype Failure
func callAsFunction(_ parameters: Parameters, completion: ((Result<Success, Failure>) -> ())?)
}
@yimajo
yimajo / Larning_EnvironmentValues.swift
Created January 23, 2020 02:24
SwiftUIのEnvironmentValuesはSubViewに伝搬するしカスタムなKeyも指定できる
/*:
# EnvironmentValuesはSubViewに伝搬するしカスタムなKeyも指定できる
- EnvironmentValuesは特定のKeyに対して値を設定できる
- 標準のKey
- https://developer.apple.com/documentation/swiftui/environmentvalues
- EnvironmentValuesが特定のViewの項目にそのまま紐付いている
- 例えば標準のKeyである\.fontはView上のTextのfontと結びついている
- Keyの値がView暗黙的にバインディングされている感じ
@yimajo
yimajo / ContentView.swift
Last active September 6, 2021 09:21
SwiftUIでBindingは参照元の値を変更できるが、Stateは参照元の値を変更できないサンプル。Playgroundで動作する。
import PlaygroundSupport
import SwiftUI
import Combine
class ObservableObject1: ObservableObject {
@Published var name: String = "src"
}
struct ContentView1: View {
@ObservedObject private var object = ObservableObject1()
@yimajo
yimajo / TDD_book_reading.md
Last active April 27, 2019 16:25
テスト駆動開発 読書録

前提

テスト駆動開発 読書録

ch1. 仮実装

  • どのようなクラスから始めるかではなくテストから始める
@yimajo
yimajo / protocol_inherit_from_class.swift
Last active March 30, 2019 06:52
Swift5からprotocolでclassをinheritできるようになった?
class Hoge {}
// Swift 5から
protocol ComponentA: Hoge {
func name() -> String
}
// Swift 4でも同じようなことはできた
protocol ComponentB where Self: Hoge {
func name() -> String
@yimajo
yimajo / quiz.kt
Last active September 6, 2018 05:00
Kotlin クイズ1
fun main(args: Array<String>) {
var value: Int? = null
println(value ?: 0 < 1) // この出力はtrueです
value = 10
println(value ?: 0 < 1) // Q. この出力は何でしょう?
}
/*:
回答の選択肢
- 10
@yimajo
yimajo / quiz.swift
Last active September 6, 2018 02:39
Swiftクイズ1
var value: Int? = nil
print(value ?? 0 < 1) // この出力はtrueです
value = 10
print(value ?? 0 < 1) // Q. この出力は何でしょう?
/*:
回答の選択肢
- 10