Create Navigation Bar Programmatically in Swift

In your UIPopoverPresentationControllerDelegate: func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? { let presentedViewController = controller.presentedViewController let navigationController = UINavigationController(rootViewController: presentedViewController) let dismissButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: “dismissPopover:”) presentedViewController.navigationItem.rightBarButtonItem = dismissButton return navigationController } func dismissPopover(sender: AnyObject) { self.dismissViewControllerAnimated(true, completion: nil) }

Setting Up Delegates in iOS

This is copied from the iOS Apprentice tutorial on raywenderlich.com but I wanted to put it where I could easily access it. These are the basic steps for setting up a delegate pattern between two objects, where object A is the delegate for object B, and object B will send messages back to A. Define a delegate protocol for… Continue reading Setting Up Delegates in iOS

Published
Categorized as tutorials Tagged

Override Application Transport Security in xCode

When you get the error App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file., you can override the security and allow all http urls through by adding this to your info.plist file: <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true> </true></dict> However, before doing this,… Continue reading Override Application Transport Security in xCode

Published
Categorized as snippets Tagged

Create keyboard shortcut to toggle Document Outline in Xcode

In Xcode, open Preferences and go to the “Key Bindings” section. Type “outline” in the search filter box. Select “Show Document Outline” and double-click to the right, in the “Key” column. A text box should appear and you can type in your new shortcut. I used Cmd+9.

Get user input in Swift

Here is a helper function that handles user input. You can just plop all this in a file called HelperFunctions.swift. /* This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, by Yong Bakos. */ import Foundation // Wait for the user to type something in the console, and return what // they type as… Continue reading Get user input in Swift

Published
Categorized as snippets Tagged

Display formatted date from DatePicker in iOS

If you have an NSDate object from a UIDatePicker and you want to display it formatted: let dateFormatter = NSDateFormatter() dateFormatter.dateStyle = NSDateFormatterStyle.MediumStyle myDateLabel.text = dateFormatter.stringFromDate(myDatePicker.date)