How we got here
Let's begin with how Viacom developers and Swift came together, but if you want the Tl;DR click here.
Like many other developers, when Swift was announced I was over the moon.
Not just for me personally, but also because I realized that most of the bugs we solved in our ObjC code at Viacom were due to:
nilwhere we didn't expect it
- obfuscated code and obscure API's
With a statically typed language and explicit optionals, most of these problems would be weeded out by the compiler.
- is easier to read (except for Smalltalk-veterans), so it's easier to onboard engineers
- has no more .h/.m, less boilerplate, less code-duplication, and generics
- while 'less code' leads to fast development and fast scanning of existing logic with human eyes, it also means less legacy code to maintain
- is more fun. Coding with playgrounds enables interactive development
- is faster and uses less memory (especially when utilizing value types)
- more 1
So after WWDC 2015, I presented this enthusiastically to my product managers, directors and most importantly my fellow developers. Despite some concerns — Swift 2 was just release and the constant Swift evolution was scary — we built our next big project entirely in Swift.
The project called
Playplex is now the platform for many Viacom brand apps including TVLand, MTV, ComedyCentral, BET, CMT and more. 2
Now while working on this project we created many small helper extensions to types provided by the Swift standard library.
Every Swift project we saw tended to have these and usually they addressed the same common problems. So, we created one common bucket for all those small utility functions that we use all the time, called ViaSwiftUtils.
This enabled us to share bug fixes, share a thorough test suite, and when Swift evolved, we only had to adjust our helper methods once.
Today we are proud to share these with the world!
So what can
ViaSwiftUtils do for you? Here are some examples we compiled:
Tired of spelling out
NSLocalizedString every time you localize a string?
title = "HomePage.title".localized print(title) // 'Main', '頭版', 'صفحه نخست', 'Startseite'
Want to find the longest word in a string?
print(germanText.longestWord()) // 'Verkehrsinfrastrukturfinanzierungsgesellschaft'
Need an array (or any other
MutableCollection) shuffled? 3
var numbers = [1, 2, 3, 4, 5, 6] numbers.shuffleInPlace() //e.g. [4, 1, 5, 2, 6, 3]
Want all the unique entries in a
let emojis = ["😀", "👀", "😱", "😡", "👀", "😀", "👀", "😱"] let uniqueEmojis = emojis.unique() // ["😀", "👀", "😱", "😡"]
Is dealing with
let twelveDays = 12 * TimeInterval.day let minutes = twelveDays / TimeInterval.minute // 17280
Need to create an image with rounded corners from an existing image?
Does one of the views in your app need to rotate?
someView.startRotating() // ... someView.stopRotating()
And more date helper methods & variables:
let components = DateComponents(calendar: gregorian, era: 0, year: 44, month: 3, day: 15, hour: 13) let idesOfMarch = gregorian.date(from: components)! let weekDay = idesOfMarch.dayOfWeek // 6 let daysSince = idesOfMarch.days(to: Date()) // 752533
These are just a few examples. We are expanding the library continuously and we accept Pull-Requests ☺️
How to install ViaSwiftUtils
Add the following line to your
Remember you'll need to enable
pod 'ViaSwiftUtils', '1.0.1'
Add the following line to your
github "ViacomInc/ViaSwiftUtils" ~> 1.0.1
Via Swift package manager
Add the following to your
.Package(url: "https://github.com/ViacomInc/ViaSwiftUtils", majorVersion: 1, minor: 0),
I should mention that only the
Foundation functions that are part of
ViaSwiftUtils work via SPM, as
UIKit is not available on Linux or MacOS.
After you installed the framework via one of the 3 above methods, import it in your
Some iOS Devs at Viacom put together a collection of miscellaneous helper methods into an open source library called ViaSwiftUtils .
All Viacom INTL iOS developers contributed to the
ViaSwiftUtils library.We also received a lot of support and encouragement to finally release it from Viacom management.
We want to thank and all developers around the world who contribute to Swift for providing us with our favorite productivity tool.
Special thanks go to Chris & Florian from objc.io for the Swift training they provided.
In 2015 we started with Latin America but apps are rolled out across the globe, so some might not yet be available in your countries app store. ↩