Skip to content

Instantly share code, notes, and snippets.

View bfernandesbfs's full-sized avatar

Bruno Fernandes bfernandesbfs

View GitHub Profile
# Type a script or drag a script file from your workspace to insert its path.
# skip if we run in debug
if [ "$CONFIGURATION" == "Debug" ]; then
echo "Skip frameworks cleaning in debug version"
exit 0
fi
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
public struct Response<Value> {
public let request: URLRequest?
public let response: HTTPURLResponse?
public let data: Data?
public let result: Result<Value>
public typealias NetworkCompletion = ((_ result: Response<Data?>) -> Void)?
public enum Method: String {
case OPTIONS, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT
}
public class Request {
fileprivate var headers: [String: String] = ["Content-Type": "application/json"]
fileprivate var task : URLSessionDataTask!
public typealias JSON = [String: Any]
public enum Result<A> {
case success(A)
case failure(Error)
public var isSuccess: Bool {
switch self {
case .success:
return true
fileprivate class SessionDelegate: NSObject, URLSessionDelegate {
// MARK: - NSURLSessionDelegate
public func urlSession(_ session: URLSession,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?)
-> Void) {
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust &&
func unique<S: Sequence, E: Hashable>(_ source: S) -> [E] where E==S.Iterator.Element {
var seen: [E:Bool] = [:]
return source.filter { seen.updateValue(true, forKey: $0) == nil }
}
let a = ["four","one", "two", "one", "three","four", "four"]
print(unique(a))
struct Person {
var name: String
override init(frame: CGRect) {
super.init(frame: frame)
loadViewFromNib()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
loadViewFromNib()
}
extension ViewController: Keyboardable {
var layoutConstraintsForKeyboard: [NSLayoutConstraint] {
return [layoutBottonTextField]
}
var addValueForKeyboard: CGFloat {
return 0
}
}
extension Keyboardable where Self: UIViewController {
public func addKeyboardObservers() {
NSNotificationCenter
.defaultCenter()
.addObserverForName(UIKeyboardWillShowNotification,
object: nil,
queue: nil) { [weak self] notification in
self?.keyboardWillShow(notification)
@bfernandesbfs
bfernandesbfs / Keyboardable.swift
Created September 20, 2016 12:45
Keyboardable protocol move
public protocol Keyboardable {
var layoutConstraintsForKeyboard: [NSLayoutConstraint] { get }
var addValueForKeyboard: CGFloat { get }
func addKeyboardObservers()
func removeKeyboardObservers()
}