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 generateRandom(length: Int) -> String { | |
let letters = ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", | |
"k", "l", "z", "x", "c", "v", "b", "n", "m"] | |
var str = "" | |
for _ in 0 ..< length { | |
str.append(letters.randomElement()!) | |
} | |
return str | |
} |
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 Notification<T> { | |
let name: NSNotification.Name | |
} | |
private let notificationData = "_notificationData" | |
extension NotificationCenter { | |
func post<T>(_ notification: Notification<T>, object: Any? = nil, data: T) { | |
post(name: notification.name, object: object, userInfo: [notificationData: data]) | |
} |
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
// UITextField | |
let textField = UITextField() | |
textField.addAction( | |
UIAction { action in | |
let textField = action.sender as! UITextField | |
print(textField.text ?? "") | |
}, | |
for: .editingChanged | |
) |
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
#define SharedApplication [UIApplication sharedApplication] | |
// open tel call | |
[SharedApplication openURL:[NSURL URLWithString:@"tel:1-408-555-5555"]]; | |
// open itunes application | |
[SharedApplication openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/numbers/id361304891?mt=8"]]; | |
// open map | |
[SharedApplication openURL:[NSURL URLWithString:@"http://maps.apple.com/?q=cupertino"]]; |
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
// | |
// GradientView.swift | |
// Notion | |
// | |
// Created by Cody Robertson on 3/16/16. | |
// Copyright © 2016 Lift, Inc. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
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
//Swift 2.0 | |
import UIKit | |
protocol SomethingDelegate { | |
func didUpdateSomething(SomethingHelper:SomethingHelper) | |
} | |
class SomethingHelper { | |
private var timer : dispatch_source_t! = nil | |
private var currentIntervalInSec = 0; | |
var delegate: SomethingDelegate? |
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
// | |
// Model.swift | |
// KidSpace | |
// | |
// Created by October Hammer on 4/19/17. | |
// Copyright © 2017 Ocotober Hammer. All rights reserved. | |
// | |
import Foundation | |
import Parse |
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 AVFoundation | |
import UIKit | |
class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { | |
var captureSession: AVCaptureSession! | |
var previewLayer: AVCaptureVideoPreviewLayer! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
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 Alamofire | |
import SwiftyJSON | |
class APIManager { | |
private init(){} | |
class func request( | |
_ url: URLConvertible, | |
method: HTTPMethod, |