Posts

Showing posts with the label Swift

Keep your option(al)s open

Image
I'm a Swift Newbie. And its humbling to say the least. But I'm definitely seeing parallels with other object oriented programming languages such as Java. One prime example is the Optional type. optionals were recently introduced to  the Java development ecosystem (JDK8) But as any Java developer would know, third party libraries such as Guava supported the optional type way before Java 8 was a thing. Guava, anyone? No, not the fruit. Check this out  for more on Guava optionals specifics. The resource also highlights some common regrets with nulls in general. In a nutshell, they suck! (thanks Doug Lea for the quote!) In short, optionals give us the option (see what I just did there) to store an existing value of a specific type or nothing at all. For example, let's say we want a variable to hold someone's middle name. Not everyone has a middle name so we want to allow the possibility of a missing value. So I want a variable called middleName to hold a person's mi...

How to play an audio file in iOS using Swift 2.0 and Xcode 7.0

Image
How to play an audio file in iOS using Swift/Xcode version 7.0 I've also been fascinated by mobile applications. But I've spent most of my career coding desktop or web based applications. So I decided to change that by taking Udacity's Intro to iOS App Development with Swift . Good decision, right? Right. For the first project, we develop a very basic application which records audio and plays it back. The first iteration requires playing a predefined audio file back at different speeds (or rates, according to AVAudioPlayer nomenclature). Below are the high level steps and code samples to play an audio file using Swift 2.0. First things first, you need an audio file, say a movie_quote.mp3 somewhere on your file system.  Locate it! Drag that file from source directory to the target directory. In this case, the target directory is the Pitch Perfect project directory in Xcode. Now the file will be made available to the application source code. Make sure you select t...