Skip to content

Instantly share code, notes, and snippets.

@tempire
tempire / ble.swift
Last active February 24, 2023 12:35
bluetooth LE advertise/scan
//
// Check.swift
// Points
//
// Created by Glen Hinkle on 10/2/16.
// Copyright © 2016 Zombie Dolphin. All rights reserved.
//
import Foundation
import CoreBluetooth
@tempire
tempire / vcs.swift
Created June 30, 2016 06:05
Typed view controller and storyboard
// Allows
// Storyboard.Main.viewController(MainVC)
enum Storyboard: String {
case Main
static let values = [Main]
static var boards = [Storyboard:UIStoryboard]()
func viewController<A: UIViewController>(type: A.Type) -> A {
@tempire
tempire / closure.m
Last active May 11, 2016 21:06
objc block closure
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated duration:(NSTimeInterval)duration completion:(void(^)(BOOL finished))completion {
void (^highlight)(UIView *, BOOL) = ^void(UIView *view, BOOL highlight) {
if (highlight) {
view.layer.borderWidth = 0.0;
view.layer.borderColor = [UIColor clearColor].CGColor;
view.layer.shadowOpacity = 0.0;
}
else {
Within a NSManagedObject subclass called "Customer"
@NSManaged var pccf: PCCF?
func findOrCreatePCCF(context: NSManagedObjectContext) -> PCCF? {
if let pccf = self.pccf {
return pccf
}
map $http_upgrade $connection_upgrade {
default "upgrade";
"" "";
}
server {
listen 80;
location / {
proxy_pass http://docker;
@tempire
tempire / uiview_nsbundle_storyboard.swift
Created October 3, 2015 01:57
UIView NSBundle Storyboard
import Foundation
import UIKit
class CustomerDetailProgressVC: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var progressListView: UIView!
let rightItemPadding: CGFloat = 10
let itemHeight: CGFloat = 60
@tempire
tempire / substr.swift
Created September 9, 2015 04:09
swift substr
//let last6 = Range(start: advance(item.id.endIndex, -6), end: item.id.endIndex)
//label.text = item.id.substringWithRange(last6)
@tempire
tempire / collectionview-beginend-updates.swift
Created August 30, 2015 10:31
collectionview begin/end coredata updates
import Foundation
import UIKit
import CoreData
class PresentationsListVC: UIViewController {
@IBOutlet weak var collectionView: UICollectionView?
// UICollectionView doesn't do beginUpdates/endUpdates.
// CoreData modifications are stored in here and performed together
//
// ViewController.swift
// PDFAttempt
//
// Created by Glen Hinkle on 3/17/15.
// Copyright (c) 2015 Zombie Dolphin. All rights reserved.
//
import UIKit
@tempire
tempire / background-vc.swift
Created August 25, 2015 01:52
present view controller on entering background
func frontViewController(window: UIWindow) -> UIViewController {
if let rootVC = window.rootViewController {
var frontVC = rootVC
while (true) {
if let vc = frontVC.presentedViewController { frontVC = vc }
else { break }
}
return frontVC