Skip to content

Instantly share code, notes, and snippets.

Nuno Gonçalves nunogoncalves

Block or report user

Report or block nunogoncalves

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nunogoncalves
nunogoncalves / ZoomableImageView.swift
Last active Jan 17, 2019
Basic zoomable image view
View ZoomableImageView.swift
//
// ZoomableImageView.swift
// ZoomableImage
//
// Created by Nuno Gonçalves on 01/04/17.
// Copyright © 2017 Nuno Gonçalves. All rights reserved.
//
import UIKit
@nunogoncalves
nunogoncalves / enums_multiple_values.swift
Last active Nov 3, 2019
Workaround to have kind of multiple values enums
View enums_multiple_values.swift
//: Playground - noun: a place where people can play
import UIKit
enum VehicleType : RawRepresentable {
struct Vehicle : Equatable {
let name: String
let wheels: Int
@nunogoncalves
nunogoncalves / Dates.swift
Last active Feb 7, 2019
Date Operations in swift 3 //Date() + 1.days
View Dates.swift
//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 / DatePicker.swift
Last active Nov 14, 2016
iOS DatePicker with just month and year (Still work in progress)
View DatePicker.swift
//
// DatePicker.swift
// CreditCard
//
// Created by Nuno Gonçalves on 13/11/16.
// Copyright © 2016 Nuno Gonçalves. All rights reserved.
//
import UIKit
@nunogoncalves
nunogoncalves / CreditCardValidation.swift
Last active May 21, 2020
Credit card validation in Swift 3
View CreditCardValidation.swift
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
View Requestable.swift
protocol Requestable {
associatedtype Element
var httpMethod: HTTPMethod { get }
var headers: HeadParams? { get }
var bodyParams: BodyParams? { get }
var encoding: RequestEncoding { get }
View Deserializable.swift
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)
View UserGetterAfter.swift
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)
}
}
View Authenticable.swift
protocol Authenticable {
var headers: HeadParams? {
get
}
func fillHeaders()
}
extension Authenticable {
var headers: HeadParams? {
View UserGetterBefore.swift
extension Users {
class Getter : Requestable {
var httpMethod = HTTPMethod.GET
var headers: HeadParams? = ["Authorization" : "Bearer \(CurrentUser.accessToken ?? "")"]
func fillHeaders() {}
var bodyParams: BodyParams? = [:]
func fillBodyParams() {}
You can’t perform that action at this time.