Skip to content

Instantly share code, notes, and snippets.


Xing He kukushi

View GitHub Profile
waylybaye / Measure.swift
Last active Jun 1, 2020
SwiftUI view render performance Indicator
View Measure.swift
// Created by Baye Wayly on 2020/3/13.
// Copyright © 2020 Baye. All rights reserved.
import SwiftUI
struct Measure<Content: View>: View {
@State var cost: TimeInterval = 0
var content: Content
init(@ViewBuilder builder: () -> Content) {
pepasflo / .gitignore
Last active Oct 18, 2019
Scripts for encrypting / decrypting secrets (to prevent them from being accidentally checked into git)
View RichTextEditor.swift
public protocol RichTextEditorDelegate: class {
func textDidChange(text: String)
func heightDidChange()
fileprivate class WeakScriptMessageHandler: NSObject, WKScriptMessageHandler {
weak var delegate: WKScriptMessageHandler?
init(delegate: WKScriptMessageHandler) {
self.delegate = delegate
mackuba /
Last active Dec 7, 2019
New stuff from WWDC 2016

Following the tradition from last year, here's my complete list of all interesting features and updates I could find in Apple's OSes, SDKs and developer tools that were announced at this year's WWDC. This is based on the keynotes, the "What's New In ..." presentations and some others, Apple's release notes, and blog posts and tweets that I came across in the last few weeks.

If for some reason you haven't watched the talks yet, I really recommend watching at least the "State of the Union" and the "What's New In" intros for the platforms you're interested in. The unofficial WWDC Mac app is great way to download the videos and keep track of what you've already watched.

If you're interested, here are my WWDC 2015 notes (might be useful if you're planning to drop support for iOS 8 now and start using some iOS 9 APIs).

OSX → macOS 10.12 Sierra

tomhut / Civic.dvtcolortheme
Created Jun 14, 2016
Xcode 7 version of the Civic theme from Xcode 8, place it in ~/Library/Developer/Xcode/UserData/FontAndColorThemes/ and restart Xcode. You will first need to acquire the SF Mono font family.
View Civic.dvtcolortheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<string>1 1 1 1</string>
<string>SFMono-Bold - 11.0</string>
<string>1 1 1 1</string>
chriseidhof / TypedExpr.swift
Last active Feb 3, 2018
Typed Expressions in Swift
View TypedExpr.swift
// Variables just contain an integer. We can have a maximum of `Int.max` variables in our program. ¯\_(ツ)_/¯
private struct Var {
static var freshVarIx = 0
let ix: Int
init() {
ix = Var.freshVarIx
plumhead / StringSize.swift
Created Sep 15, 2015
String extension to find the layout size of a String with specified attributes.
View StringSize.swift
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
mackuba /
Last active Apr 9, 2020
New stuff from WWDC 2015

Here's my own list of the interesting stuff announced during this year's WWDC, collected from the keynotes, various Apple docs, blog posts and tweets.

If you're planning to watch the videos, I really recommend this Mac app that helps you download and watch them:

OS X El Capitan

  • split view - two apps side by side on full screen
nicklockwood / gist:21495c2015fd2dda56cf
Last active Mar 31, 2020
Thoughts on Swift 2 Errors
View gist:21495c2015fd2dda56cf

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

View SerializationExperiment.swift
import Foundation
protocol Serializable {
static func deserializeInto(bytePtr: UnsafeMutablePointer<UInt8>, bytes: ArraySlice<UInt8>) -> ArraySlice<UInt8>
extension Serializable {
typealias WorkaroundSelf = Self
You can’t perform that action at this time.