Skip to content

Instantly share code, notes, and snippets.

@bwhiteley
bwhiteley / MyWKInterfaceController.swift
Last active August 29, 2015 14:12
Ensure UI updates to WatchKit Interface Controller only happen while the controller is active.
/*
"WatchKit ignores attempts to set values of interface objects
while your interface is inactive.... Modifications can be made
only during initialization of your interface controller and
between calls to willActivate and [didDeactivate]."
*/
class MyWKInterfaceController: WKInterfaceController {
private var isActive:Bool = true
@bwhiteley
bwhiteley / wwdc_alert.sh
Last active December 16, 2015 14:49
My WWDC ticket alert system. Run in screen on linux.
#!/bin/bash
theSite="https://developer.apple.com/wwdc/"
foo=$(curl $theSite)
echo $foo
oldFile=$(date +"%Y-%m-%d-%H_%M_%S").start
echo "$foo" > $oldFile
while true; do
@bwhiteley
bwhiteley / Nil.swift
Last active March 2, 2017 08:31
NilLiteralConvertible can lead to surprising behavior
struct Foo : CustomStringConvertible {
let text:String
init(text:String) {
self.text = text
}
var description:String { return self.text }
}
class DetailViewController: UIViewController {
@IBOutlet var label: UILabel! {
didSet {
label?.text = episode.title
}
}
let episode: Episode
init(episode: Episode) {
@bwhiteley
bwhiteley / screenRecordingToGIF.sh
Created December 12, 2017 23:05
Create GIF from screen recording (or other video)
#!/bin/sh
# https://superuser.com/questions/436056/how-can-i-get-ffmpeg-to-convert-a-mov-to-a-gif
# Requires ffmpeg and ImageMagick
INPUT=$1
OUTPUT=$2
TMP=giffer_tmp_$$.gif
@bwhiteley
bwhiteley / stats.swift
Created February 27, 2019 06:41
naive statistics playground for kid's homework.
import Foundation
func mean(_ values: [Float]) -> Float {
return sum(values) / Float(values.count)
}
func median(_ values: [Float]) -> Float {
var sorted = values.sorted()
guard values.count > 0 else { return 0 }
while sorted.count > 2 {

To start using Carthage with a new project:

  1. List your dependencies in a Cartfile. Refer to the Carthage documentation for details.
  2. Run carthage bootstrap --no-build --use-submodules
  3. Create a new workspace.
  4. Drag your existing App project into the workspace.
  5. Drag framework dependency projects from ./Carthage/Checkouts into the workspace.
  6. Go to the General tab of your target properties.
  7. Add framework dependencies to Linked Frameworks and Libraries. They will show up as Workspace frameworks.
  8. Add the same frameworks to Embedded Binaries.
  9. Note, the previous step will probably create duplicates in Linked Frameworks and Libraries. Delete the duplicates.
@bwhiteley
bwhiteley / HostingView.swift
Last active June 16, 2023 04:47
Host SwiftUI in a UIView
import Foundation
import SwiftUI
#if os(macOS)
public typealias PlatformViewType = NSView
#elseif !os(watchOS)
import UIKit
public typealias PlatformViewType = UIView
#endif
#if !os(watchOS)
@bwhiteley
bwhiteley / gist:049e4bede49e71a6d2e2
Last active March 17, 2024 13:10
Initialize Swift subclass of UIView, designed in .xib
// Create CustomView.xib, set File's Owner to CustomView.
// Link the top level view in the XIB to the contentView outlet.
class CustomView : UIView {
@IBOutlet private var contentView:UIView?
// other outlets
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()