This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func addUserToAddressBook(contact: User){ | |
let stat = ABAddressBookGetAuthorizationStatus() | |
switch stat { | |
case .Denied, .Restricted: | |
println("no access to addressbook") | |
case .Authorized, .NotDetermined: | |
var err : Unmanaged<CFError>? = nil | |
var adbk : ABAddressBook? = ABAddressBookCreateWithOptions(nil, &err).takeRetainedValue() | |
if adbk == nil { | |
println(err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspiration: https://gist.github.com/NinoScript/47819cf6fe36d6845aee32d19b423e9b | |
//: Playground - noun: a place where people can play | |
import UIKit | |
enum SavableEnum { | |
case simpleCase | |
case associatedValue(String) | |
case anotherAssociated(Int) | |
} | |
extension SavableEnum { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Alamofire // installation instructions for Alamofire can be found here: https://github.com/Alamofire/Alamofire | |
// Sends text message to phone number | |
func sendText(phoneNumber: String, message: String) { | |
let apiKey = "AccessKey YOUR_ACCES_KEY" | |
let originator = "YOUR_NAME" | |
// create a new manager instance (so you don't overwrite any other API's authorization) | |
var manager = Manager.sharedInstance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// just add random-backgroundcolor to the element you want to give a random background color | |
app.directive("randomBackgroundcolor", function () { | |
return { | |
restrict: 'EA', | |
replace: false, | |
link: function (scope, element, attr) { | |
//generate random color | |
var color = '#' + (Math.random() * 0xFFFFFF << 0).toString(16); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String { | |
func containsNumbers() -> Bool { | |
// check if there's a range for a number | |
let range = self.rangeOfCharacterFromSet(.decimalDigitCharacterSet()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VerticalCenteredTextView: UITextView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
addContentSizeObserver() | |
} | |
override init(frame: CGRect, textContainer: NSTextContainer?) { | |
super.init(frame: frame, textContainer: textContainer) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CartographyExtensions.swift | |
// portkey | |
// | |
// Created by Samuel Beek on 14/06/16. | |
// | |
// Note: still WIP. I only dealt with the equality operator (==), haven't worked on <= and ~ yet. | |
// But adding this won't be bad for you project, it saves me 70% compile time per block on avarage. | |
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Platform | |
{ | |
static let isSimulator: Bool = { | |
var isSim = false | |
#if arch(i386) || arch(x86_64) | |
isSim = true | |
#endif | |
return isSim | |
}() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://krakendev.io/force-touch-recognizers/ | |
// Without this import line, you'll get compiler errors when implementing your touch methods since they aren't part of the UIGestureRecognizer superclass | |
import UIKit.UIGestureRecognizerSubclass | |
//Since 3D Touch isn't available before iOS 9, we can use the availability APIs to ensure no one uses this class for earlier versions of the OS. | |
@available(iOS 9.0, *) | |
public class ForceTouchGestureRecognizer: UIGestureRecognizer { | |
//Since it also doesn't make sense to have our force variable as a settable property, I'm using a private instance variable to make our public force property read-only | |
private var _force: CGFloat = 0.0 | |
NewerOlder