Skip to content

Instantly share code, notes, and snippets.

View dars's full-sized avatar

Devlin dars

  • code4soul
  • Taiwan,Taipei
View GitHub Profile
@sgr-ksmt
sgr-ksmt / StoryboardInstantiatable.swift
Last active October 12, 2023 09:11
Create UIViewController from storyboard and pass parameter safely.
public protocol StoryboardInstantiatable {
static var storyboardName: String { get }
static var viewControllerIdentifier: String? { get }
static var bundle: Bundle? { get }
}
public extension StoryboardInstantiatable where Self: UIViewController {
public static var storyboardName: String {
return String(describing: self)
}
@phatmann
phatmann / BackgroundTask.swift
Created April 15, 2015 03:14
Encapsulate iOS background tasks in a Swift class
class BackgroundTask {
private let application: UIApplication
private var identifier = UIBackgroundTaskInvalid
init(application: UIApplication) {
self.application = application
}
class func run(application: UIApplication, handler: (BackgroundTask) -> ()) {
// NOTE: The handler must call end() when it is done