Sitting at a Street Bean – coffee shop right next to my work. I started at Code Fellows a little less then a year ago thinking this will be my long term gig. Since then I’ve met a lot of energetic software engineers, passionate management… essentially people who care about changing people’s lives for the greater good… this is my last week here. Next week I start at Nike.
In addition to teaching iOS, I have spent the time covering data structures and helping students get ready for interviews. Learning how to “code” is only half the battle… I am sure most of my friends would agree.
What I’ve noticed is that typical interview questions evolve around Linked Lists, Palindromes, Base Conversion, Binary Search trees, etc. You might never use these data structures in production, but they come up quite often on interviews and thus are important to know if you want to get a job. In this article I will cover 3 questions and write implementation in Swift 3. Linked Lists topic has been covered pretty extensively already by other developers… I won’t bother.
Continue reading “Palindromes, Base 16 & Roman Numerals”
Some time ago, my friend Monty and I considered integrating Medium API into our app, in.notes. At that time their API was relatively young and unpolished.
A couple of days ago I decide to take another look at it. What started as a single class with two functions for token retrieval turned into a full blown OAuth client with Keychain support. If you would rather skip the explanation and go straight to sample code, here it is!
I should mention that I tried keeping my implementation somewhat flexible to support other APIs. I agree that it would have been much better to work with at least two end points to map out similarities, my current implementation can be modded with relative ease in the future.
Continue reading “Medium OAuth Client for iOS”
Generics are awesome. In fact, they are insanely cool when it comes to writing reusable code. To demonstrate their usefulness, let’s build a generic Cache storage.
Our cache should meet the following requirements:
- Should be fast (read, write) – O(1)
- Support hashable data type (NSData, UIImage, String, Int, etc)
- Support custom size to allow for initialization based on memory limitations
- Should keep track and clear out oldest objects before adding new ones
- Should keep recently accessed data by marking it as the most recent
Before writing code, let’s talk about implementation. For starters, I will use a dictionary to store the actual data. Reason behind using a dictionary (or a hash table) should be rather obvious… both the lookup and insertion of data takes constant time. This will be especially useful when dealing with large cache size.
Continue reading “Swift Generics – Cache”
It [Swift 3.0] is inevitable. – Agent Smith
We are getting pretty close to the release of Swift 3.0. Part of me is very excited (fifty percent of me, to be precise). Since a few of my projects are completely written in Swift, no Objective-C, I decided to dive into Swift 3.0 with the release of a toolchain snapshot. I was particularly interested in quantifying the amount of effort it will require to update my apps (I like to migrate my code manually and see new changes rather then using auto-migration tool shipped with Xcode).
Needless to say, my project secretly named “Cobra (think of Jesse from the Burn Notice) – Update to Swift 3.0” wasn’t successful. It is way too early. I still managed to get a simple project setup and got myself familiarized with the new syntax – awesome. By the way, Playgrounds don’t work.
If you are interested, here are simple steps on how to use the Swift 3.0 Preview Toolchain in current version of Xcode (7.3.1).
First of all, head over to www.swift.org and download the latest snapshot (direct link here).
Once downloaded, run the package installer. This will install the new toolchain. Next, you’ll need to go to Xcode / Toolchains and select Swift 3.0 Preview 1 Snapshot. You’ll be asked to restart Xcode…
From here, it is time to test the waters and create a new project. I would suggest starting with a Single View Application template… a couple of warnings and compiler errors later, you are on your way to write your code.
Happy Swift 3.0 writing…
UPDATE: I successfully updated my project to Swift 3.0.
Unbreakable encryption is possible. Welcome to One-time Pad or what also referred to as “the perfect cipher”. To be honest, it is comforting to know that it is possible to encrypt text conversations to the point where it is practically impossible to decrypt without having the correct key. While the previous two ciphers mentioned earlier (Caesar Cipher and Vigenere Cipher) provide a way to scramble text into “gibberish”, both can be easily decrypted using pattern matching without needing the original key.
Unlike previous crypto algorithms, Vernam uses random key composed of random numbers to encrypt text. It is a very simple, yet powerful algorithm as you will see shortly.
Continue reading “Vernam Cipher in Swift”
Today I decided to take a look at the upcoming Swift 3.0 changes. If you are interested in reading about implemented proposals, please see Swift Evolution page on Github. This article is in addition to the article I wrote about Swift 2.2 changes that can be found here.
SE-0003: Removing var from Function Parameters – is the one I want to talk about. Function parameters, by default, are constants. However, it was possible to declare the parameter as a variable.
Continue reading “Mutable Function Parameters”
Like everybody else, I spent a few hours this week updating my personal projects to Swift 2.2 which was released with Xcode 7.3 a few days ago. Updating to Swift 2.2 was important in my case since 2.2 version is basically an intermediate release between Swift 2.0 and the upcoming 3.0 version. This prompted me to take a few moments and write about the changes I had to implement in my code. There is a nice write up about the changes on www.swift.org if you are interested in more details.
Continue reading “Swift 2.2 Changes”