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/Foundation.h> | |
extern NSString *addressBookErrorDomain; | |
typedef NS_ENUM(NSInteger, AddressBookError) { | |
AddressBookErrorOK, | |
AddressBookErrorNoAddressBook, | |
AddressBookErrorNoAccess | |
}; |
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
// | |
// UIViewController+GetImage.swift | |
// | |
// Created by Daniel Tartaglia on 4/25/16. | |
// Copyright © 2016 MIT License | |
// | |
import UIKit | |
import PromiseKit |
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
// | |
// UIColorExtensions.swift | |
// | |
// Created by Daniel Tartaglia on 12/4/14. | |
// Copyright (c) 2014 Daniel Tartaglia. MIT License. | |
// | |
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
// | |
// AppStore.swift | |
// | |
// Created by Daniel Tartaglia on 1/10/17. | |
// Copyright © 2017 Daniel Tartaglia. MIT License. | |
// | |
import Foundation | |
import StoreKit |
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
// | |
// Dispatcher.swift | |
// Flux | |
// | |
// Created by Daniel Tartaglia on 3/13/17. | |
// Copyright © 2017 Daniel Tartaglia. MIT License. | |
// | |
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
// | |
// ViewController.swift | |
// | |
// Created by Daniel Tartaglia on 1/27/17. | |
// Copyright © 2017 Daniel Tartaglia. MIT License. | |
// | |
import UIKit | |
class ViewController: UIViewController |
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
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { | |
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { | |
let image = (info[UIImagePickerControllerEditedImage] as? UIImage) ?? (info[UIImagePickerControllerOriginalImage] as? UIImage) | |
if let data = image.flatMap({ UIImageJPEGRepresentation($0, 0.8)} ) { | |
api.upload(avatar: data).then { [weak self] in | |
self?.avatarView.image = image | |
self?.dismiss(animated: true, completion: nil) | |
} | |
.catch { [weak self] error in |
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
extension UIViewController | |
{ | |
@discardableResult | |
func displayInformationAlert(title: String, message: String) -> Promise<Void> { | |
return Promise(queue: DispatchQueue.main) { fulfill, _ in | |
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) | |
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in fulfill() })) | |
self.present(alert, animated: true, completion: nil) | |
} | |
} |
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 ViewController: UIViewController | |
{ | |
@IBAction func changeAvatar(_ sender: UITapGestureRecognizer) { | |
guard let senderView = sender.view else { fatalError("Tapped on viewless gesture recognizer?") } | |
let controller = UIImagePickerController() | |
controller.delegate = self | |
choiceIndexUsingActionSheet(title: "", message: "", choices: sourceOptions.map { $0.title }, onSourceView: senderView).then { index in | |
sourceOptions[index].action(controller) | |
self.present(controller, animated: true, completion: nil) | |
} |
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 ImagePickerDelegate: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate | |
{ | |
let promise = Promise<UIImage>() | |
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { | |
if let image = (info[UIImagePickerControllerEditedImage] as? UIImage) ?? (info[UIImagePickerControllerOriginalImage] as? UIImage) { | |
promise.fulfill(image) | |
} | |
else { | |
promise.reject(UIImagePickerControllerError.missingImage) |
OlderNewer