Skip to content

Instantly share code, notes, and snippets.

View avaidyam's full-sized avatar

Aditya Vaidyam avaidyam

View GitHub Profile
@jackreichert
jackreichert / Keychain.swift
Last active January 11, 2017 02:43 — forked from s-aska/Keychain.swift
Swift Keychain class ( supported Xcode Version 7.0 beta 4 (7A165t) )
import UIKit
import Security
class Keychain {
class func save(key: String, data: NSData) -> Bool {
let query = [
kSecClass as String : kSecClassGenericPassword as String,
kSecAttrAccount as String : key,
kSecValueData as String : data ]
public enum TruncateMode {
case Head, Middle, Tail
}
public extension String {
/// Truncates a string to a maximum length in grapheme clusters using the
/// specified mode. If `addEllipsis` is `true`, the resulting string
/// including the ellipsis will be no longer than `maxLength`.
func truncateToLength(maxLength: Int, mode: TruncateMode = .Tail, addEllipsis: Bool = false) -> String {
if maxLength <= 0 {