Skip to content

Instantly share code, notes, and snippets.

@minsOne
minsOne / dynamicMemberLookup Builder
Last active July 13, 2023 07:22
dynamicMemberLookup Builder
// refer: https://woowabros.github.io/swift/2021/02/18/swift-dynamic-features.html
@dynamicMemberLookup
public struct Builder<Base: AnyObject> {
private var base: Base
public init(_ base: Base) {
self.base = base
}
import UIKit
import AXSnapshot
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
do {
let label = UILabel(frame: .init(x: 100, y: 100, width: 100, height: 100))
15a16
> -interpret Immediate mode
17a19
> -repl REPL mode (the default if there is no input file)
20,22c22,45
< -application-extension Restrict code to those available for App Extensions
< -assert-config <value> Specify the assert_configuration replacement. Possible values are Debug, Release, Replacement.
< -color-diagnostics Print diagnostics in color
---
> -application-extension Restrict code to those available for App Extensions
@minsOne
minsOne / NSObject+setValuesForKeysWithJSONDictionary.h
Created February 15, 2023 02:48 — forked from markd2/NSObject+setValuesForKeysWithJSONDictionary.h
Support files for Inside the Bracket Part 6, showing an actual use of the objective-C runtime API.
//
// NSObject+setValuesForKeysWithJSONDictionary.h
//
// Created by Tom Harrington on 12/29/11.
// Tweaked by Mark Dalrymple
//
// Copyright (c) 2011 Atomic Bird, LLC. All rights reserved.
//
#import <Foundation/Foundation.h>
@minsOne
minsOne / Runtime.swift
Last active February 14, 2023 09:30 — forked from codelynx/Runtime.swift
[Swift] To retrieve classes at runtime which conforms to a protocol or to retrieve subclasses of a given class
//
// Runtime.swift
// Swift Runtime [Swift 4]
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@minsOne
minsOne / AppDelegate.swift
Last active December 30, 2022 00:14
Network Abstract Layer
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GitHubAPI.Users(userName: "minsone").request(completion: { result in
print(result)
})
}
}
@minsOne
minsOne / ContentView.swift
Created October 30, 2022 13:26 — forked from nathanborror/ContentView.swift
SwiftUI wrapper around Slack's PanModal (https://github.com/slackhq/PanModal)
import SwiftUI
import PanModal
struct ExampleView: View {
@State var detail: AnyView? = nil
@State var items: [String] = ["Detail 1", "Detail 2", "Detail 3"]
var body: some View {
NavigationView {
@minsOne
minsOne / Data+PrettyPrint.swift
Created October 24, 2022 01:36 — forked from cprovatas/Data+PrettyPrint.swift
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@minsOne
minsOne / AccessibilityPreview.swift
Created October 18, 2022 10:31 — forked from Sherlouk/AccessibilityPreview.swift
SwiftUI view for adding accessibility previews. Proof of concept.
import SwiftUI
import UIKit
// from https://github.com/cashapp/AccessibilitySnapshot
import AccessibilitySnapshotCore
struct AccessibilityPreview<Content: View>: View {
let content: Content
var body: some View {
@minsOne
minsOne / generate.rb
Last active September 26, 2022 04:44
#!/usr/bin/env ruby
def find_interface_type(key, path)
cmd = <<SHELL
cat #{path} | grep "property descriptor for #{key}.type :" | sed -E "s/.* : (.*)\\?/\\1/g"
SHELL
#puts cmd
value = `#{cmd}`
#puts value
return value.strip