Skip to content

Instantly share code, notes, and snippets.

View nunogoncalves's full-sized avatar

Nuno Gonçalves nunogoncalves

View GitHub Profile
@nunogoncalves
nunogoncalves / BetterDecodingError.swift
Last active January 26, 2024 08:37
Better Decoding Error Messages
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 / 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
import UIKit
class ViewController: UIViewController {
let tableView: UITableView = {
let tv = UITableView(frame: .zero, style: .plain)
tv.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
return tv
}()
@nunogoncalves
nunogoncalves / dropbox_delete_all_links.js
Last active April 4, 2022 10:16
More or less automatic way to delete all links in dropbox. Since they don't provide a way of doing so and it's very boring to delete one by one when you have hundreds of links...
@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 / Loading elipsis animation.swift
Last active June 12, 2021 00:12
Setting an ellipsis changing from 1 to 3 dots
//Set a NSTimer to update call this function every n seconds to provide desired effect.
var numberOfDots = 3
func applySearchingEffect() {
if let str = label.text {
let range = NSMakeRange(str.length - numberOfDots, numberOfDots)
var string = NSMutableAttributedString(string: str)
string.addAttribute(NSForegroundColorAttributeName, value: UIColor.clearColor(), range: range)
label.attributedText = string
@nunogoncalves
nunogoncalves / ScreenshotServiceDelegate.swift
Created March 19, 2020 19:42
ScreenshotServiceDelegate
func screenshotService(
_ screenshotService: UIScreenshotService,
generatePDFRepresentationWithCompletion completionHandler: @escaping (Data?, Int, CGRect) -> Void
) {
...
}
@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 / 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 / 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