Skip to content

Instantly share code, notes, and snippets.

View reeichert's full-sized avatar
🏠
Working from home

João Reichert reeichert

🏠
Working from home
View GitHub Profile
@reeichert
reeichert / AppManager+Tutorial.swift
Created May 17, 2017 13:41
Should show tutorial
public class AppManager: NSObject {
static let userDefaults = UserDefaults.standard
static let shared = AppManager()
static let dataKey = "AppManagerDataKey"
static let tutorialKey = "AppManagerTutorialKey"
public func reset(for key: String) {
if var data = userDefaults.object(forKey: dataKey) as? [String: Bool] {
data.removeValue(forKey: key)
@reeichert
reeichert / TrabalhoCalculoNumericoEuler.swift
Last active August 10, 2017 04:10
Trabalho de calculo numérico onde é apresentado a Formula de Euler, Euler melhorado e Runge Kutta para calcular uma EDO de circuito elétrico de 2 ordem.
// Site utilizado para execução durante a apresentação
// https://swift.sandbox.bluemix.net/
import Foundation
// Extensão utilizada para arredondar as casas decimais
extension Double {
func roundTo(_ places:Int) -> Double {
let divisor = pow(10.0, Double(places))
@reeichert
reeichert / ClosedConvexHullCLLocationCoordinate2D.swift
Created August 13, 2017 00:57
Closed convex hull CLLocationCoordinate2D
func sortConvex(input: [CLLocationCoordinate2D]) -> [CLLocationCoordinate2D] {
// X = longitude
// Y = latitudeß
// 2D cross product of OA and OB vectors, i.e. z-component of their 3D cross product.
// Returns a positive value, if OAB makes a counter-clockwise turn,
// negative for clockwise turn, and zero if the points are collinear.
func cross(P: CLLocationCoordinate2D, A: CLLocationCoordinate2D, B: CLLocationCoordinate2D) -> Double {
let part1 = (A.longitude - P.longitude) * (B.latitude - P.latitude)
@reeichert
reeichert / heightWithConstrainedWidth.swift
Last active May 16, 2019 22:09
heightWithConstrainedWidth
extension String {
func heightWithConstrainedWidth(width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
let boundingBox = self.boundingRect(with: constraintRect,
options: .usesLineFragmentOrigin,
attributes: [NSAttributedString.Key.font: font],
context: nil)
return boundingBox.height
}
@reeichert
reeichert / RealmExtension.swift
Created December 26, 2017 14:47
Realm helper
import Foundation
import RealmSwift
var realmConfiguration: Realm.Configuration?
public typealias VoidCompletion = () -> Void
extension Realm {
static var shared: Realm? {
@reeichert
reeichert / Devices.swift
Created January 3, 2018 17:10
Screen sizes
import UIKit
public struct Screen {
/// Retrieves the device bounds.
public static var bounds: CGRect {
return UIScreen.main.bounds
}
/// Retrieves the device width.
public static var width: CGFloat {
@reeichert
reeichert / UITableView+.swift
Created February 18, 2019 21:20
Extension that make easier to add UIView or UIViewController as Header of UITableView
//
// UITableView+.swift
//
// Created by Joao Reichert on 18/02/19.
// Copyright © 2019 Reichert. All rights reserved.
//
import UIKit
extension UITableView {
@reeichert
reeichert / KeychainPasswordItem.swift
Created January 23, 2020 20:12
KeychainPasswordItem from Apple Inc
/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
A struct for accessing generic password keychain items.
*/
import Foundation
import Foundation
/// Provides a default value for missing `Decodable` data.
///
/// `DefaultCodableStrategy` provides a generic strategy type that the `DefaultCodable` property wrapper can use to provide a reasonable default value for missing Decodable data.
public protocol DefaultCodableStrategy {
associatedtype RawValue: Codable
static var defaultValue: RawValue { get }
}
@reeichert
reeichert / UIView+AutoLayout.swift
Last active September 7, 2022 00:20
AutoLayout helpers
//
// File.swift
//
//
// Created by João Reichert on 06/09/22.
//
import UIKit
public extension UIView {