Swift Pair Programming – Session 7


Fantastic pair programming session with Nick last night. In the span of 1 hour we solved a datatype casting issue and set up CoreLocation on a new project.

Last week we were stumped authenticating with Twitter through an p2/OAuth. The code was built to OAuth into github. I had an hour after work so I looked for another OAuth library and found OAuthSwift.

Unfortunately it doesn’t build. I tried it both ways. Once with a Podfile to install. And another time dragging in the xcodeproject file and adding the framework to the target’s Build Phase. No Dice.

Building the app fails with 366 errors. “That’s cool,” I thought. I’ll just update the code to Swift 3 syntax. Minutes later, do another build.

Great. Only 306 errors.

I switched it up and switched targets to the demo build within the OAuthSwift project. Hit build, still errors errors errors.

I wasn’t satisfied with the outcome. What am I doing wrong? 

I got the idea to test building against a trivial open source app on github written in swift. Enter FlappySwift, a nice little flappy bird clone. NOTE TO SELF: Use this framework to build Mathogen in Swift with SKSprites.

FlappySwift built with no errors!

The issue was not with my Xcode installation or configuration. It’s in the OAuthSwift library. I was in the middle of submitting an issue to the maintainers of OAuthSwift when Nick called me on ScreenHero to start our pairing session.

We visited for a bit and talked about how we each spent our respective Thanksgivings. I shared that I had been working on OAuthSwift for the past hour. And we decided to shift our focus of the night to other things.

OAuthSwift, you’re still in my sights. I will get you to work!

We decided to make a list of the things we wanted to pursue next. Nick had an issue with an NSObject passed in a local notification. This weekend I added push notifications to my app and learned that my app needs to have a https connection in order to receive push notifications. I did a hacky workaround that allowed for http but felt weird about it.

I suggested working on creating SSL certificates with LetsEncrypt, but it seems kind of server based. The pairing session is for iOS pairing!

We decided to focus on Nick’s Notification code. Here’s the finished code:

//: Playground - noun: a place where people can play

import UIKit
import CoreLocation

var str = "Hello, playground"

//enum NotificationTitle {
//    static  NotificationToPostName
typealias payloadDict = [String: AnyObject]

class ReceivingClass: NSObject {

func registerForNotification() {

NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "TheNotification") , object: nil, queue: nil, using: { notification in
let tuple: (CLLocation, String) = notification.object as! (CLLocation, String)

class BroadcastClass: NSObject {

func postNotification()  {

let myTuple: (CLLocation, String) = (CLLocation.init(latitude: 12.1, longitude: 12.2), "The String")

let notification = Notification.init(name: Notification.Name(rawValue: "TheNotification"), object: myTuple , userInfo:nil )

let receivingClass = ReceivingClass()
let broadcastClass = BroadcastClass()


Here’s the exact place in the code we were able to sort it out:

let tuple: (CLLocation, String) = notification.object as! (CLLocation, String)

Can you see where the object in the tuple needed to be casted before it was printed? The tuple holds a string but the compiler doesn’t know that. It needs to know that this data is a string or else it’s like, WTF man?

Having made quick progress squashing that bug, Nick asked me what I wanted to focus on.

I said I was interested in GPS. I haven’t worked on any projects that have used GPS yet. We dove in and created a quick project. After the session Nick posted it to github. You can check it out here: Stalker.

Programmers come up with silly names for their projects to keep ourselves from throwing the computer out the window🙂

Over the course of the rest of the pairing session I learned the following:

  • In order to add GPS functionality you need to add keys and values to the plist
  • Set the values with strings that will come up in the alert.
  • Call Background Execution to keep the app polling for updated locationDo the location requests in the View Controller

Before the next meeting I am going to do the following:

  • Check out the swift style guide.
  • Read the rest of the fuckingswiftsyntax
  • Check out crashlytics for showing
  • Can add a bash script to run on start up.
  • Add a new buildphase and run the script there.
  • Create PCH file: pre-compiled header file in objective C to hold OAuth tokens and keys.
  • Use typealias to set the kind of datatype you want to use. EG: typealias payloadDict = [String :AnyObject]
  • Write all code in Swift 3.

And here are some unsorted extras:

  • Command + 1 to zoom in on the simulator.
  • Asked Nick how he learns. Videos? Nope, gets into a blog post or a how to and just dips in and dips out. We agreed that we both get stuck and a little fatigued learning the entire codebase at once. Good to dip in and out of documentation.

Looking forward to the next pair programming session! In other news, the first Hawaii iOS Developer Meetup is tonight at the Manoa Innovation Center at 5pm. See you there!

Author: David Neely

Professional Software Developer. Technology and Web Coordinator at the University of Hawaii's Manoa Career Center.