Numbers are the building blocks of any piece of software. It eventually gets all the way down to our code being translated into a series of numbers that refer to specific CPU instructions and data to use with them. We will stay well above that level in this post, but I thought it would be useful to share some of the special aspects of how numbers, particularly Integers, are handled in Swift.
[Read more…]
Swift Set Type
In Objective-C there were three basic types of Data Structures, NSArray, NSDictionary, and NSSet. In Objective-C, the immutable and mutable forms were separate, so you also had NSMutableArray, NSMutableDictionary, and NSMutableSet. Especially since it is often an interview question, I should point out that a Data Structure is simply “a particular way of organizing data in a computer so that it can be used efficiently.” You can read that sentence and more at the Wikipedia article about Data Structures.
In Swift we were greeted with Arrays and Dictionaries, but there was no Set to be found! You had to go back to Objective-C’s NSSet to work with them. You can read about the other two Data Structures back in the previous posts Arrays and their Methods in Swift and Swift Dictionary Quick Reference. Well, thanks to Swift 1.2, Set has come to the land of Swift.
[Read more…]
Multiple Optional Bindings in Swift
Shortly after my last post Segue from UITableViewCell Taps in Swift, Apple released Xcode 6.3 Beta 1, which includes Swift 1.2. There are many updates to the language that I was quite happy about, but let’s talk about my favorite one today, improved Optional Binding.
The new version allows you to bind multiple optionals, as well as check a boolean expression related to them in a single line, avoiding the nesting we currently must do when working with multiple Optional Bindings.
[Read more…]
Segue from UITableViewCell Taps in Swift
In many apps that use a UITableView, when a UITableViewCell is tapped, the screen will segue over to another view, such as how choosing a song in the Music app goes to the Now Playing screen, and plays that song, shows the album art, and other metadata about the song. This can be done programmatically in tableView:didSelectRowAtIndexPath:, but with Storyboards, it is even easier. All we have to do is set up a segue, and treat it pretty much exactly like we did in Segue between Swift View Controllers.
To avoid an even longer setup section, and to not cover things we already covered, we’re going to start with the result of the previous post Getting Started With UITableView in Swift.
Anyway, starting from where we left off, let’s set up the storyboard.
[Read more…]
How to Dismiss UITextField’s Keyboard in your Swift App
If you need to take text input in your Swift app, you will probably need a UITextField. It is exactly what it sounds like, just a field on the screen where the user types something in. When the user taps on it, the keyboard comes up from the bottom of the screen, and allows the user to start typing. Then, usually, when the user clicks outside of the UITextField, the keyboard is dismissed, and the cursor is no longer in that UITextField.
However, a common issue for many iOS programming beginners is that the last part of that story isn’t built in. If you just plop on a UITextField, and try tapping somewhere else…. nothing happens. That’s what we’re here to fix today.
[Read more…]
- « Previous Page
- 1
- 2
- 3
- 4
- 5
- …
- 16
- Next Page »