Skip to content

Instantly share code, notes, and snippets.

View davidahouse's full-sized avatar

David House davidahouse

View GitHub Profile
@davidahouse
davidahouse / migrator.rb
Created September 29, 2016 11:49
Run the Swift 3 migrator for a project manually from the command line rather than letting Xcode do it
require 'find'
require 'pp'
swift_file_paths = []
Find.find('./') do |path|
if path =~ /.*\.swift$/ and !path.start_with? "./Carthage"
swift_file_paths << path
cmd = "xcrun swift-update -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -target arm64-apple-ios9 #{path} > convert.swift"
system cmd
@davidahouse
davidahouse / UIHostingController+Extension.swift
Created November 19, 2020 12:35
Capture a SwiftUI view to a UIImage
extension UIHostingController {
func capture() -> UIImage {
let size = sizeThatFits(in: UIScreen.main.bounds.size)
view.bounds.size = size
view.sizeToFit()
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.isOpaque, 0)
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
let snapshotImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()