Skip to content

Instantly share code, notes, and snippets.

@unledrob
unledrob / Reduce.swift
Last active January 14, 2017 04:59
Using reduce to convert an array to a dictionary in Swift
let playersArray: [[String: String]] = [
["number": "1", "name": "De Gea", "position": "G"],
["number": "3", "name": "Bailly", "position": "D"],
["number": "6", "name": "Pogba", "position": "M"],
["number": "9", "name": "Ibrahimovic", "position": "F"],
["number": "8", "name": "Mata", "position": "M"],
["number": "10", "name": "Rooney", "position": "F"]
]
let playersDictionary = playersArray.reduce([String:[String:String]](), { (dict, tuple) in
@unledrob
unledrob / MobileScreenshots.sh
Last active February 1, 2017 22:42
A bash script for taking screenshots via the Genymotion emulator or iOS Simulator. More info in the comments...
# iOS screenshots to get around El Cap Xcode 8.2.1 issue
# http://stackoverflow.com/a/41125408/84783
# Android / Genymotion screenshots
# http://stackoverflow.com/a/24316765/84783
function ss() {
i="0"
while true; do
filename=~/Desktop/$1_$2_`printf %02d $i`.png
if [ "$1" == "ios" ]; then
xcrun simctl io booted screenshot $filename
@unledrob
unledrob / InstalledFonts.swift
Created July 15, 2017 14:16
Get the installed font for an iOS application. This helps instantiating a new UIFont by name since the name is sometimes not apparent. Note: be sure to add the font to Info.plist first.
// THANKS: http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
for family: String in UIFont.familyNames {
print("\(family)")
for names: String in UIFont.fontNames(forFamilyName: family) {
print("== \(names)")
}
}