Skip to content

Instantly share code, notes, and snippets.

View nunogoncalves's full-sized avatar

Nuno Gonçalves nunogoncalves

View GitHub Profile
extension Users {
class Getter : Requestable {
var httpMethod = HTTPMethod.GET
var headers: HeadParams? = ["Authorization" : "Bearer \(CurrentUser.accessToken ?? "")"]
func fillHeaders() {}
var bodyParams: BodyParams? = [:]
func fillBodyParams() {}
protocol Authenticable {
var headers: HeadParams? {
get
}
func fillHeaders()
}
extension Authenticable {
var headers: HeadParams? {
extension Users {
class Getter : Requestable, WebGetter, Authenticable, EmptyBody, UrlEncodable, Deserializable {
var deserializer = Deserialize.UserDeserializer()
var url = "https://..."
func getUserDetails(success success: User -> (), failure: ApiResponse -> ()) {
call(success: success, failure: failure)
}
}
protocol Deserializable {
associatedtype T: Deserializer
var deserializer: T { get }
func getDataFrom(dictionary: NSDictionary) -> T.MappedObject
}
extension Deserializable {
func getDataFrom(dictionary: NSDictionary) -> T.MappedObject {
return deserializer.buildFrom(dictionary)
protocol Requestable {
associatedtype Element
var httpMethod: HTTPMethod { get }
var headers: HeadParams? { get }
var bodyParams: BodyParams? { get }
var encoding: RequestEncoding { get }
@nunogoncalves
nunogoncalves / CreditCardValidation.swift
Last active October 7, 2021 07:51
Credit card validation in Swift 3
import UIKit
import PlaygroundSupport
//http://stackoverflow.com/questions/72768/how-do-you-detect-credit-card-type-based-on-number
enum CreditCardType {
case visa
case visaElectron
case mastercard
@nunogoncalves
nunogoncalves / DatePicker.swift
Last active September 13, 2022 19:52
iOS DatePicker with just month and year (Still work in progress)
//
// DatePicker.swift
// CreditCard
//
// Created by Nuno Gonçalves on 13/11/16.
// Copyright © 2016 Nuno Gonçalves. All rights reserved.
//
import UIKit
@nunogoncalves
nunogoncalves / Dates.swift
Last active February 7, 2019 15:10
Date Operations in swift 3 //Date() + 1.days
//See the bottom of this file to check what you can do with this
let calendar = Calendar(identifier: .gregorian)
struct CalendarComponentAmount {
let component: Calendar.Component
let amount: Int
}
infix operator +: AdditionPrecedence
@nunogoncalves
nunogoncalves / enums_multiple_values.swift
Last active November 3, 2019 18:02
Workaround to have kind of multiple values enums
//: Playground - noun: a place where people can play
import UIKit
enum VehicleType : RawRepresentable {
struct Vehicle : Equatable {
let name: String
let wheels: Int
@nunogoncalves
nunogoncalves / ZoomableImageView.swift
Last active January 17, 2019 12:24
Basic zoomable image view
//
// ZoomableImageView.swift
// ZoomableImage
//
// Created by Nuno Gonçalves on 01/04/17.
// Copyright © 2017 Nuno Gonçalves. All rights reserved.
//
import UIKit