Skip to content

Instantly share code, notes, and snippets.

Avatar

Nuno Gonçalves nunogoncalves

View GitHub Profile
@nunogoncalves
nunogoncalves / BetterDecodingError.swift
Last active Oct 3, 2020
Better Decoding Error Messages
View BetterDecodingError.swift
import Foundation
enum BetterDecodingError: CustomStringConvertible {
case dataCorrupted(_ message: String)
case keyNotFound(_ message: String)
case typeMismatch(_ message: String)
case valueNotFound(_ message: String)
case any(_ error: Error)
@nunogoncalves
nunogoncalves / CreditCardValidation.swift
Last active Sep 17, 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 ScreenshotserviceViewControllerDelegate.swift
import UIKit
class ViewController: UIViewController {
let tableView: UITableView = {
let tv = UITableView(frame: .zero, style: .plain)
tv.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
return tv
}()
View ScreenshotServiceDelegate.swift
func screenshotService(
_ screenshotService: UIScreenshotService,
generatePDFRepresentationWithCompletion completionHandler: @escaping (Data?, Int, CGRect) -> Void
) {
...
}
@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 / 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
View man xccov
xccov(1) xccov(1)
NAME
xccov - view Xcode coverage data in human-readable or machine-parseable format.
SYNOPSIS
xccov view [--only-targets | --files-for-target target_name | --functions-for-file name_or_path]
@nunogoncalves
nunogoncalves / env-vars.sh
Last active Apr 10, 2018
Local environment variables
View env-vars.sh
export GITHUB_CLIENT_ID=<valid_id>
export GITHUB_CLIENT_SECRET=<valid_secret>
View GithubCreds.swift
struct GithubCreds {
static let clientId = "CLIENT ID"
static let clientSecret = "CLIENT SECRET"
}
You can’t perform that action at this time.