Skip to content

Instantly share code, notes, and snippets.

Bart Whiteley bwhiteley

Block or report user

Report or block bwhiteley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bwhiteley
bwhiteley / HostingView.swift
Created Sep 16, 2019
Host SwiftUI in a UIView
View HostingView.swift
open class HostingView<Content> : UIView where Content : View {
private let hostingVC: UIHostingController<Content>
public var rootView: Content {
get { return hostingVC.rootView }
set { hostingVC.rootView = newValue }
}
public init(rootView: Content) {
@bwhiteley
bwhiteley / stats.swift
Created Feb 27, 2019
naive statistics playground for kid's homework.
View stats.swift
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 {
@bwhiteley
bwhiteley / screenRecordingToGIF.sh
Created Dec 12, 2017
Create GIF from screen recording (or other video)
View screenRecordingToGIF.sh
#!/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
View UIViewController with Xib
class DetailViewController: UIViewController {
@IBOutlet var label: UILabel! {
didSet {
label?.text = episode.title
}
}
let episode: Episode
init(episode: Episode) {
View Carthage.md

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 / Nil.swift
Last active Mar 2, 2017
NilLiteralConvertible can lead to surprising behavior
View Nil.swift
struct Foo : CustomStringConvertible {
let text:String
init(text:String) {
self.text = text
}
var description:String { return self.text }
}
@bwhiteley
bwhiteley / MyWKInterfaceController.swift
Last active Aug 29, 2015
Ensure UI updates to WatchKit Interface Controller only happen while the controller is active.
View MyWKInterfaceController.swift
/*
"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 / gist:049e4bede49e71a6d2e2
Last active Jun 25, 2019
Initialize Swift subclass of UIView, designed in .xib
View gist:049e4bede49e71a6d2e2
// 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()
@bwhiteley
bwhiteley / wwdc_alert.sh
Last active Dec 16, 2015
My WWDC ticket alert system. Run in screen on linux.
View wwdc_alert.sh
#!/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
You can’t perform that action at this time.