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
/* | |
File: KeychainItemWrapper.h | |
Abstract: | |
Objective-C wrapper for accessing a single keychain item. | |
Version: 1.2 - ARCified | |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple | |
Inc. ("Apple") in consideration of your agreement to the following | |
terms, and your use, installation, modification or redistribution of |
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
APIManager.signInUser("fer", password: "fer", successBlock: { (user) -> () in | |
print(user) | |
}) { | |
failureBlock: { error in | |
print(error) | |
} |
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
// A beautiful two-closure method. | |
signInUser("fer", pass: "quetzalmx") { User in | |
// Success | |
print(User) | |
}.onFailure { error in | |
// Failure | |
print(error) | |
} | |
// Calls a function that returns an object which can optionally fail. |
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 | |
// LambdaEnums | |
// | |
// Created by Fernando Olivares on 11/1/19. | |
// Copyright © 2019 Fernando Olivares. All rights reserved. | |
// | |
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
extension UIImageView { | |
/// Loads image from web asynchronosly and caches it, in case you have to load url | |
/// again, it will be loaded from cache if available | |
func load(url: URL, placeholder: UIImage?, cache: URLCache? = nil) { | |
let cache = cache ?? URLCache.shared | |
let request = URLRequest(url: url) | |
if let data = cache.cachedResponse(for: request)?.data, let image = UIImage(data: data) { | |
self.image = image | |
} else { | |
self.image = placeholder |
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
#!/bin/bash | |
# This way you can customize which branches should be skipped when | |
# prepending commit message. | |
if [ -z "$BRANCHES_TO_SKIP" ]; then | |
BRANCHES_TO_SKIP=(master develop test) | |
fi | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
BRANCH_NAME="${BRANCH_NAME##*/}" |
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 requestAuthorization(completion: ((Bool, Error?) -> Void)? = nil) { | |
// enable local notifications (alarms in background) | |
let authorizationOptions: UNAuthorizationOptions | |
if #available(iOS 12.0, *) { | |
authorizationOptions = [.badge, .alert, .sound, .criticalAlert] | |
} else { | |
authorizationOptions = [.badge, .alert, .sound] | |
} | |
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 requestAuthorization(completion: @escaping (Result<Bool, Error>) -> Void) { | |
var authorizationOptions: UNAuthorizationOptions = [.badge, .alert, .sound] | |
if #available(iOS 12.0, *) { | |
authorizationOptions.insert(.criticalAlert) | |
} | |
let notificationCenter = UNUserNotificationCenter.current() | |
notificationCenter.requestAuthorization(options: authorizationOptions) { (granted, possibleError) 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
protocol CurrencyPickerProtocol : class { | |
func selected(currency: String, from: CurrencyPickerTableViewController) | |
} | |
class CurrencyPickerTableViewController: UITableViewController { | |
weak var delegate: CurrencyPickerProtocol | |
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
let key = order[indexPath.row] |
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
// Behavior 1: Save to preferences. | |
class CurrencyPickerSettingsResponsible { } | |
extension CurrencyPickerSettingsResponsible : CurrencyPickerProtocol { | |
func selected(currency: String, from: CurrencyPickerTableViewController) { | |
let preferences = BTCPreferences.sharedPreferences() | |
preferences.setObject(key, forKey: kBTCSelectedCurrencyKey) | |
preferences.synchronize() | |
NSNotificationCenter.defaultCenter().postNotificationName(kBTCCurrencyDidChangeNotificationName, object: key) |
OlderNewer