Skip to content

Instantly share code, notes, and snippets.

@0si43
0si43 / ButtonWrapperUsingUIViewPropertyAnimator.swift
Created August 26, 2021 07:55
A sample code using UIViewPropertyAnimator
import UIKit
/// ラッパークラス
final class ButtonWrapperUsingUIViewPropertyAnimator {
private var button: UIButton!
private var bar: UIView!
private let completion: () -> Void
init(completion: @escaping () -> Void) {
self.completion = completion
@0si43
0si43 / CAButtonWrapper.swift
Last active August 26, 2021 07:58
A sample code using Core Animation
import UIKit
/// ラッパークラス
final class CAButtonWrapper {
private var button: UIButton!
private var bar: UIView!
private let completion: () -> Void
init(completion: @escaping () -> Void) {
self.completion = completion
@0si43
0si43 / tips.md
Last active October 1, 2021 06:00
Tips: Markdownで内部のファイル・画像へのリンクを貼るときの記法

ディレクトリ構造

root
|
+-- tips.md
+-- tips2.md
+-- img --- image.png

ファイル

@0si43
0si43 / mapWithKeyPath.swift
Created November 9, 2021 02:32
KeyPathを使うと任意のプロパティでmapできて便利
class Res {
let temp = "temp"
}
let reses = [Res(), Res(), Res()]
print(reses.map(\.temp)) // ["temp", "temp", "temp"]
@0si43
0si43 / AnyPublisherUseCase.swift
Created November 9, 2021 07:57
`.eraseToAnyPublisher()`の意味がわからんなかったので調べたやつ
// from:
// https://developer.apple.com/documentation/combine/just/erasetoanypublisher()
import Combine
public class TypeWithSubject {
public let publisher: some Publisher = PassthroughSubject<Int,Never>()
}
public class TypeWithErasedSubject {
public let publisher: some Publisher = PassthroughSubject<Int,Never>()
@0si43
0si43 / branch_all_delete.sh
Created November 16, 2021 09:37
不要なブランチを全部消す
// https://zenn.dev/yumiyoshi/scraps/363a710df362b8
git branch | xargs git branch -d
@0si43
0si43 / HeaderViewDelegate.swift
Created December 13, 2021 02:12
ボツにしたけど、こんなこともできるよなprotocol
protocol HeaderViewDelegate: AnyObject {
var HeaderPresenter: HeaderPresenter { get }
func showAlert(of _: Error)
}
extension HeaderViewDelegate where Self: UIViewController {}
@0si43
0si43 / github_image_embeded_specific_size.html
Created December 13, 2021 09:03
Githubに画像埋めこむときにサイズを調整したい
// iPhone 12 Proのアスペクト比
<img src="url" height="844" width="390">
@0si43
0si43 / JSONResponseDecoder.swift
Created December 23, 2021 10:30
JSONをparseするときにスネークケースを自動変換してくれるオプション
keyDecodingStrategy = .convertFromSnakeCase
@0si43
0si43 / SwiftUI_Group_onAppear.swift
Created December 28, 2021 05:36
iOS 15ではViewが呼ばれた際に発火するが、iOS 14では呼ばれないため注意
Group {
// view logic
}
.onAppear {
// do something
}