Skip to content

Instantly share code, notes, and snippets.

View yutailang0119's full-sized avatar

Yutaro Muta yutailang0119

View GitHub Profile
@yutailang0119
yutailang0119 / LocalizedText.swift
Last active April 17, 2021 09:56
Localized Text for SwiftUI
import Foundation
import SwiftUI
protocol TextLocalizable {
var `default`: String { get }
var enUS: String { get }
var jaJP: String { get }
// TODO: Implement others of Locale.availableIdentifiers
}
@yutailang0119
yutailang0119 / ConvertAtoB.swift
Last active October 22, 2020 10:38
AをBに変換するCombine.Publisher拡張を作りたい
import UIKit
import Combine
struct A {
let name: String
}
struct B {
let text: String
}
@yutailang0119
yutailang0119 / .github-workflows-languages.yml
Last active July 12, 2020 16:58
Posting language lists to Mackerel with GitHub Actions
# Place it in .github/workflows/languages.yml
name: Repositoy Languages
on:
push:
branches:
- master
jobs:
@yutailang0119
yutailang0119 / MockAPIClient+Combine.swift
Last active May 31, 2020 07:40
Mock Swift APIClient with Combine
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, macCatalyst 13.0, *)
// MARK: - Request
protocol Request {
associatedtype Response: Decodable
var urlRequest: URLRequest { get }
}
// MARK: - APISession
@yutailang0119
yutailang0119 / CrashSwiftUIPopover.swift
Created January 25, 2020 07:54
SwiftUI.View.popover(isPresented: Binding<Bool>) doesn't crashed, but SwiftUI.View.popover(item: Binding<Identifiable?>) crashes on dismiss Popover.
import SwiftUI
/*
This works fine.
*/
struct NonCrashView: View {
@State private var isPopup: Bool = false
var body: some View {
Button("Foo") {
@yutailang0119
yutailang0119 / DebuggerView.swift
Last active January 6, 2020 16:44
Debugging View for SwiftUI
import SwiftUI
import PlaygroundSupport
public struct DebuggerView<Body: View>: View {
private let _body: Body
private let color: Color
public init(body: Body, color: Color? = nil) {
self._body = body
import Foundation
var value: Any = "value"
@propertyWrapper
struct Wrapper<Value> {
private let defaultValue: Value
init(defaultValue: Value) {
self.defaultValue = defaultValue
import Foundation
@propertyWrapper
struct UserDefault<Value> {
private let key: String
private let defaultValue: Value
private let defaults: UserDefaults
init(key: String, defaultValue: Value, defaults: UserDefaults = .standard) {
self.key = key
import Foundation
import Combine
protocol Request {
associatedtype Response: Decodable
var resource: Data { get }
}
struct User: Decodable {
let name: String
@yutailang0119
yutailang0119 / UIColor+Hex.swift
Last active March 12, 2019 02:37
UIColor extension for HexColor
extension UIColor {
convenience init(hex string: String, alpha: CGFloat) {
let hex = string.replacingOccurrences(of: "#", with: "")
let scanner = Scanner(string: hex)
var color: UInt32 = 0
if scanner.scanHexInt32(&color) {
let r = CGFloat((color & 0xFF0000) >> 16) / 255.0
let g = CGFloat((color & 0x00FF00) >> 8) / 255.0
let b = CGFloat(color & 0x0000FF) / 255.0
self.init(red: r, green: g, blue: b, alpha: alpha)