Skip to content

Instantly share code, notes, and snippets.

@fikeminkel
fikeminkel / ServiceAvailability.swift
Created April 15, 2018 13:08
this one with an enum to force type safety. really messy though.
import UIKit
enum ServiceId {
case service(id: String)
func id() -> String {
switch self {
case .service(let id): return id
}
}
}
import UIKit
class Service {
typealias ServiceId = String
let id: ServiceId
init(id: ServiceId) {
self.id = id
}
}
@fikeminkel
fikeminkel / DNSTxtRecord.swift
Created April 26, 2017 20:56
Swift 3.1 DNS TXT record lookup
import dnssd
struct DNSTxtRecord {
typealias DNSLookupHandler = ([String: String]?) -> Void
static func lookup(_ domainName: String, completionHandler: @escaping DNSLookupHandler) {
var mutableCompletionHandler = completionHandler // completionHandler needs to be mutable to be used as inout param
let callback: DNSServiceQueryRecordReply = {
(sdRef, flags, interfaceIndex, errorCode, fullname, rrtype, rrclass, rdlen, rdata, ttl, context) -> Void in
struct API {
typealias Result = () throws -> JSON
enum Error: ErrorType {
case ConnectionError(NSError?)
case ServerError(statusCode: Int, message: String?)
case JSONError(NSError?)
}
}
@fikeminkel
fikeminkel / AppDelegate.swift example
Last active July 12, 2016 19:16
Sample application:didFinishLaunchingWithOptions
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
GlobalAppearance.setup()
NewRelic.enableFeatures([NRMAFeatureFlags.NRFeatureFlag_NSURLSessionInstrumentation, NRMAFeatureFlags.NRFeatureFlag_HttpResponseBodyCapture])
NewRelic.startWithApplicationToken("AA0c7adbf8d4ae29c081f35bd0764243d19a44b5fb");
NewRelic.setMaxEventBufferTime(1)
NRLogger.setLogLevels(0xffff)
...
}