A popular collection of answers to Stack Overflow questions, featured solutions, highly rated responses and dozens of earned bounties.
Collection of Swift Recipes, Gists and Xcode Projects.
Portrait & Landscape Orientation Mix & Match
SO-41433100 (Download Swift Recipe)
Special Instructions: None
Animating Toolbars out of sight while changing iPhone orientation
SO-41198069 (Download Swift Recipe)
Special Instructions: Change the Initial View Controller in Interface Builder to experiment with the different implementation variations. Notice that the smoothest, simplest solutions involve exactly zero lines of code.
See animation here.
Moving a Webview and a Toolbar
SO-41291054 (Download Swift Recipe)
Special Instructions: See animation here.
UITableView Cell Height iOS Bug
SO-35260912 (Download Swift Recipe)
Special Instructions: This causes `UILabel` to be incorrectly clipped in an AutoLayout environment. In the attached project, you will notice that changing the `estimatedRowHeight` value, as well as the `reloadData` invocation has various effects on the label, which is still sometimes clipped.
Automatic UITextView & UITextField using AutoLayout
SO-35259289 (Download Swift Recipe)
Special Instructions: Scrolling editable text into sight is notoriously difficult. This solution demonstrates throttled refresh, which alleviates or annihilates flickering generally associated with long text.
Change alpha of the Image of a UIButton
SO-35040233 (Download Swift Recipe)
Special Instructions: Use in Interface Builder with `@IBDesignable` and `@IBInspectable` for live preview.
Custom & Standard Separators for UITableViewCell
SO-35001392 (Download Swift Recipe)
Special Instructions: Compare implementation, and notice that there are exactly 0 lines of code delta between standard separators and in-cell separator. It is all handled at the resource level. Cell separators, in addition, will only be present when a cell exists.
Resize Table View Cells on Selection
SO-34996964 (Download Swift Recipe)
Special Instructions: None.
Activating & Deactivating UITextField using Responder
SO-34985404 (Download Swift Recipe)
Special Instructions: Try out with successive selection, or by dismissing keyboard.
Keywords: `UIResponder` `resignFirstResponder` `becomeFirstResponder`
Reading a text field from iOS Settings
SO-34905431 (Download Swift Recipe)
Special Instructions: Run with and without the Setting being set, compare output.
Import Objective-C Pods Framework into Swift
SO-34553684 (Download Swift Recipe)
Special Instructions: run
pod install
…then open the workspace (not the project).
Android-like ScrollView in iOS Interface Builder
SO-34139812 (Download Swift Recipe)
Special Instructions: Look at the relative relationships between the `UIScrollView`, the content `UIView`, and the 3 `UILabel` & constraints which define the sizes of what needs to be displayed.
Size Classes in Interface Builder
SO-33987900 (Download Swift Recipe)
Special Instructions: none.
Dynamic loading images in UITableView
SO-33975355 (Download Swift Recipe)
Special Instructions: Change the number of cells to load as many Wikipedia images as you want.
Adding a Toolbar to a TableView
SO-33863028 (Download Swift Recipe)
Special Instructions: none.
UITabBar with a Blur Visual Effect
SO-33819852 (Download Swift Recipe)
Special Instructions: none. Download the 1×1 clear.png.
Target-based localization
SO-33694785 (Download Swift Recipe)
Special Instructions: This example specifically addresses multiple targets with a single localization each. For the general and preferred approach, see Shared localizations across targets.
Scroll Animation in a Label
SO-33632266 (Download Swift Recipe)
Special Instructions: none.
AVAudioPlayer, multiple, simultaneous playback
SO-32768352 (Download Swift Recipe)
Special Instructions:
- record on •
- playback on main thread >
- playback on background thread >>
Intercept Taps on UIWebView in order to add Popover menu
SO-32670551 (Download Swift Recipe)
Special Instructions: none.
Integrate C, C++, Objective-C, Objective-C++ & Swift in the same Xcode project (all at once)
SO-32541268 (Download Swift Recipe)
Special Instructions: none.
Hello World in C Hello World in C++ Hello World in Objective-C Hello World in Objective-C++ Hello World in Swift
How to let the iOS or OS X pick the San Francisco Font in a CSS
SO-32408973 (Download Swift Recipe) (view HTML)
Special Instructions: none.
PrepareForSegue from a UIButton inside a UITableViewCell
SO-32341629 (Download Swift Recipe)
Special Instructions: none.
Record and Play Audio on iOS using AVAudioRecorder and Swift
SO-32342486 (Download Swift Recipe)
Special Instructions: none.
Communication between a UIWebview and Embedded Javascript
SO-32322397 (Download Swift Recipe)
Special Instructions: none.
Facebook & Parse Integration iOS & Swift Tutorial
SO-32302877 without Parse (Download legacy Swift Recipe)
Special Instructions: Run `pod install`, open `.xcworkspace`.
SO-32302877 + Parse (Download Swift Recipe)
Special Instructions: Run `pod install`, open `.xcworkspace`.
Navigation Bar and Web View (UINavigationController + UIWebview) Obj-C, Swift, Storyboard
SO-32277486 (Download Swift Recipe) (Legacy Obj-C)
Special Instructions: none.
Architecture of UITabBarController & embedded UIViewController using UINavigationController
SO-32258452 (Download Swift Recipe)
Special Instructions: none.
Changing the interface orientation of a UITabBarController
SO-32255151 (Download Swift Recipe)
Special Instructions: none.
Design UITableview section header in Interface Builder
SO-31693901 (Download Swift Recipe)
Special Instructions: none.
GameCenter Multiplayer using GCHelper
SO-31699439 (Download Swift Recipe)
Special Instructions: Run `pod install`, open `.xcworkspace`. Make `authenticationChanged` public.
Integrating and using a COCOAPOD Framework in Swift
SO-31642385 (Download Swift Recipe)
Special Instructions: Run `pod install`, open `.xcworkspace`.
import PubNub var client:PubNub? self.client = PubNub()
Get Notified when Someone Makes an In-App Purchase
SO-32021855 (Download Swift Recipe)
Special Instructions: Run `pod install`, open `.xcworkspace`.
if let mixpanel = Mixpanel.sharedInstance() { mixpanel.track( "Purchased", properties:["productIdentifier":t.payment.productIdentifier]) }
Add a Custom Color Palette to Interface Builder
SO-31702193 (Download Swift Recipe)
Special Instructions: Use Interface Builder to change the color.
Cross-Fade Animation while changing Text
SO-3073520 (Download Swift Recipe)
Special Instructions: none.
Move Toolbar Up & Down based on Keyboard and the Predictive Accessory View
SO-25946121 (Download Swift Recipe)
Special Instructions: none.
Parallax Effect with UIScrollView
SO-22201729 (Download Swift Recipe)
Special Instructions: none.
Triggering a Segue from a custom TableViewCell in iOS
SO-19778484 (Download Swift Recipe)
Special Instructions: none.
How can an item be removed from UIPasteboard
SO-19172176 (Download Swift Recipe)
Special Instructions: none.
UITableViewHeaderFooterView, XIB, Colors, alpha channel
SO-15604900 (Download Swift Recipe)
Use background view to control appearance.
Special Instructions: Use `UITableViewHeaderFooterView` does not respond well to `backgroundColor`, `contentView.backgroundColor` or `tintColor`.
Scroll Edit Text without listening to Keyboard Notifications
SO-14465447 (Download Swift Recipe)
Use exactly 0 lines of code to handle keyboard notifications.
Special Instructions: Use `UITableViewController` to handle automatic scrolling of text editing views, no notifications!