Skip to content

Instantly share code, notes, and snippets.

View danielt1263's full-sized avatar

Daniel Tartaglia danielt1263

View GitHub Profile
class ViewController: UIViewController
{
@IBOutlet weak var avatarView: UIImageView!
var api: API!
var imagePickerDelegate: ImagePickerDelegate!
@IBAction func changeAvatar(_ sender: UITapGestureRecognizer) {
guard let senderView = sender.view else { fatalError("Tapped on viewless gesture recognizer?") }
extension UIViewController
{
func getImage(focusView: UIView) -> Promise<UIImage> {
var delegate: ImagePickerDelegate! = ImagePickerDelegate()
let controller = UIImagePickerController()
controller.delegate = delegate
let result = choiceIndexUsingActionSheet(title: "", message: "", choices: sourceOptions.map { $0.title }, onSourceView: focusView).then { (index) -> Promise<UIImage> in
sourceOptions[index].action(controller)
self.present(controller, animated: true, completion: nil)
return delegate.promise
class ViewController: UIViewController
{
@IBOutlet weak var avatarView: UIImageView!
var api: API!
@IBAction func changeAvatar(_ sender: UITapGestureRecognizer) {
guard let senderView = sender.view else { fatalError("Tapped on viewless gesture recognizer?") }
getImage(focusView: senderView).then { image -> Promise<UIImage> in
@danielt1263
danielt1263 / Regex.swift
Last active May 1, 2017 23:53
Make regexs simpler in Swift.
//
// Regex.swift
//
// Created by Daniel Tartaglia on 2/6/16.
// Copyright © 2016 Daniel Tartaglia. MIT License.
//
import Foundation
//
// DelayScheduler.swift
//
// Created by Daniel Tartaglia on 4/20/17.
// Copyright © 2017 Daniel Tartaglia. MIT License.
//
final class DelayScheduler: ImmediateSchedulerType {
init(delay: TimeInterval, queue: DispatchQueue = .main) {
@danielt1263
danielt1263 / DictionaryExtensions.swift
Last active May 27, 2017 19:53
Swift Extensions... These are extensions to Swift standard types that I find useful.
//
// DictionaryExtensions.swift
//
// Created by Daniel Tartaglia on 6/18/16.
// Copyright © 2016 Daniel Tartaglia. MIT License.
//
extension Dictionary {
@danielt1263
danielt1263 / UITextField+Extensions.swift
Last active July 20, 2017 19:28
Allows you to set the text in a UITextField *without* changing the position of the cursor.
//
// UITextField+Extensions.swift
//
// Created by Daniel Tartaglia on 8/8/16.
// Copyright © 2016 MIT License.
//
import UIKit
enum UserInteractionError: Error {
case userCanceled
}
extension UIViewController
{
func choiceIndexUsingActionSheet(title: String, message: String, choices: [String], onSourceView view: UIView) -> Promise<Int> {
return Promise(queue: DispatchQueue.main) { fulfill, reject in
let alert = UIAlertController(title: title.isEmpty ? nil : title, message: message.isEmpty ? nil : message, preferredStyle: .actionSheet)
@danielt1263
danielt1263 / Redux.swift
Last active November 27, 2017 15:06
My Redux like implementation.
//
// Redux.swift
//
// Created by Daniel Tartaglia on 01/16/15.
// Copyright © 2017. MIT License.
//
public final class Store<State, Action> {
@danielt1263
danielt1263 / ViewController.swift
Created August 21, 2018 02:20
Rx DataSource custom implementation example.
//
// Created by Daniel Tartaglia on 4/20/17.
// Copyright © 2017 Daniel Tartaglia. MIT License.
import UIKit
import RxSwift
import RxCocoa
class ViewController: UIViewController {