Skip to content

Instantly share code, notes, and snippets.

View stleamist's full-sized avatar

Dongkyu Kim (Max.kim) stleamist

View GitHub Profile
@stleamist
stleamist / PageView.swift
Created May 19, 2020 11:08
A representation of UIPageViewController in SwiftUI.
import SwiftUI
struct PageView<Page: View>: UIViewControllerRepresentable {
var pages: [Page]
@Binding var currentPage: Int
func makeUIViewController(context: Context) -> UIPageViewController {
let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)
import SwiftUI
struct _DisclosureIndicator: View {
var body: some View {
Image(systemName: "chevron.forward")
.imageScale(.small)
.font(.body.weight(.semibold))
.foregroundColor(.primary.opacity(0.25))
}
}
import Foundation
import KeychainAccess
@propertyWrapper
struct KeychainStorage<Value: Codable> {
let key: String
let service: String
let initialValue: Value
@stleamist
stleamist / UIButton+BackgroundColor.swift
Last active June 26, 2022 05:52
An UIButton extension to set the color of its background, supporting dynamic colors introduced in iOS 13.
//
// UIButton+BackgroundColor.swift
// An UIButton extension to set the color of its background, supporting dynamic colors introduced in iOS 13.
//
// Created by Dongkyu Kim on 2020/01/15.
// Copyright © 2020 Dongkyu Kim. All rights reserved.
//
import UIKit
import KingFisher
struct KFLinkPresentationIconProvider: ImageDataProvider {
let url: URL
let cacheKey: String
init(url: URL, cacheKey: String? = nil) {
self.url = url
self.cacheKey = cacheKey ?? url.absoluteString
@stleamist
stleamist / extractViewsFromContent.swift
Created May 19, 2020 10:36
An experimental way to extract SwiftUI views from an TupleView built by ViewBuilder.
import SwiftUI
func extractViewsFromContent<Content: View> (@ViewBuilder content: () -> Content) -> [Any] {
let tupleView = content()
let tupleViewMirror = Mirror(reflecting: tupleView)
let tuple = tupleViewMirror.children.first!.value
let tupleMirror = Mirror(reflecting: tuple)
let views = tupleMirror.children.map { $0.value }
return views
}
@stleamist
stleamist / MailComposer.swift
Last active June 2, 2021 13:28
MFMailComposeViewController for SwiftUI
import MessageUI
import SwiftUI
struct MailComposer {
struct MessageBody {
var body: String
var isHTML: Bool
}
#!/bin/sh
PRODUCT_BUNDLE_VERSION=$(date "+%Y%m%d%H%M")
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${PRODUCT_BUNDLE_VERSION}" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${PRODUCT_BUNDLE_VERSION}" "${PROJECT_DIR}/${INFOPLIST_FILE}"
import Swift
extension Result {
func casting<NewSuccess, NewFailure>() -> Result<NewSuccess, NewFailure>? {
switch self {
case .success(let success as NewSuccess) where Failure.self is NewFailure.Type: return .success(success)
case .failure(let failure as NewFailure) where Success.self is NewSuccess.Type: return .failure(failure)
default: return nil
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.