Skip to content

Instantly share code, notes, and snippets.

@Erkened
Erkened / AppDelegate.swift
Last active February 22, 2017 10:44
How to programmatically create the initial view controller, window etc. Swift 3.0
//
// AppDelegate.swift
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
@Erkened
Erkened / Snippets.strings
Last active September 28, 2017 13:48
Snippets of Swift code I reuse often
/*
// TO APPLY DIFFERENT STRINGS FROM VARIANTS.STRINGS RATHER THAN LOCALIZABLE.STRINGS
var localised:String
{
return Bundle.main.localizedString(forKey:self, value:Bundle.main.localizedString(forKey:self, value:nil, table:nil), table:"variants")
}
// TO CONTROL THE LINE HEIGHT OF AN ATTRIBUTED STRING (LIKE TAB BAR BUTTONS)
let paragraphStyle = NSMutableParagraphStyle()
//
// UIButton_Underlined.swift
// Audio Y
//
// Created by Jonathan Neumann on 31/10/2015.
// Copyright © 2015 Audio Y Ltd. All rights reserved.
//
import UIKit
@Erkened
Erkened / Functions.swift
Last active July 4, 2017 16:00
Functions I reuse often in my apps. Swift 3.0
//
// Functions.swift
// Repnote
//
// Created by Jonathan Neumann on 23/03/2017.
// Copyright © 2017 Audioy. All rights reserved.
//
import Foundation
import UIKit
// HOW TO USE PRIVATE COCOAPODS
// SOURCE: http://albertodebortoli.github.io/blog/2014/03/11/cocoapods-working-with-internal-pods/
// SOURCE: https://coderwall.com/p/7ucsva/private-cocoapods
// SOURCE: http://product.hubspot.com/blog/architecting-a-large-ios-app-with-cocoapods
0. INSTALL COCOAPODS
sudo gem install cocoapods
1. CHECK REPOS LOCATION, WHICH SHOULD BE EMPTY
cd ~/.cocoapods/repos/
@Erkened
Erkened / MergeStringsIntoOneMD5Hash.swift
Last active February 1, 2016 14:39
Method to XOR multiple strings into one MD5 hexadecimal hash string in Swift 2. This means that [string1, string2, string3] gives the same MD5 hash as [string3, string2, string1]
// Remember to #import <CommonCrypto/CommonCrypto.h> in the Bridging-Header.h file
/* Example of use
let query = "#test1 #test2 #test3"
let queryArray = query.characters.split{$0 == "#"}.map(String.init)
guard let hash = combineStringsIntoHash(queryArray) else{
return
}
print("hash: \(hash)")
*/
@Erkened
Erkened / UITextViewWithPlaceholder
Created January 11, 2017 15:26
A UITextView subclass with placeholder. Swift 3.0
//
// UITextViewWithPlaceholder.swift
// Repnote
//
// Created by John Neumann on 11/01/2017.
// Copyright © 2017 Audioy. All rights reserved.
//
import UIKit
@Erkened
Erkened / UIScrollViewWithKeyboard
Last active January 29, 2017 19:23
A UIScrollView which scrolls when the keyboard is displayed/hidden. The keyboard is dismissed when tapping outside a responding view like a textfield or textview. Swift 3.0
//
// UIScrollViewWithKeyboard.swift
// Repnote
//
// Created by John Neumann on 29/01/2017.
// Copyright © 2017 Audioy. All rights reserved.
//
import UIKit
@Erkened
Erkened / .bash_profile
Last active January 30, 2018 15:14
Personal bashrc and bash_profile for Terminal on Mac
#!/bin/bash
#
# echo "Loading ${HOME}/.bash_profile"
#source ~/.profile # get my PATH setup
source ~/.bashrc # get my Bash aliases
@Erkened
Erkened / Extensions
Last active September 27, 2017 09:18
Extensions I use often in my projects. Swift 4.0
import Foundation
import UIKit
extension UIColor{
class var random: UIColor {
let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0
let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white
let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1)
}