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
  • 21:56 (UTC +09:00)
View GitHub Profile
@yimajo
yimajo / TDD_book_reading.md
Last active April 27, 2019 16:25
テスト駆動開発 読書録

前提

テスト駆動開発 読書録

ch1. 仮実装

  • どのようなクラスから始めるかではなくテストから始める
@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 / 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 / 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 / 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 / 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 / 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? {
import UIKit
import PhotosUI
class ViewController: UIViewController {
@IBAction func presentPickerForImagesIncludingLivePhotos(_ sender: Any) {
presentPicker(filter: PHPickerFilter.images)
}
private func presentPicker(filter: PHPickerFilter) {
import Foundation
import MobileCoreServices
import CoreImage
public struct JPEGConverter {
let data: Data
let dataUTI: String
public init(data: Data, with dataUTI: String) {
self.data = data
@yimajo
yimajo / Makefile
Last active June 1, 2023 03:11
Swift Packageでapple/swift-formatを入れた場合のMakefileの例
XCRUN = /usr/bin/env xcrun --sdk macosx
SWIFT_FORMAT_PATHS = <フォーマットしたいパス>
format:
$(XCRUN) swift run -c release \
swift-format --mode format --recursive --in-place $(SWIFT_FORMAT_PATHS)
format-skip-build :
$(XCRUN) swift run -c release --skip-build \
swift-format --mode format --recursive --in-place $(SWIFT_FORMAT_PATHS)