Skip to content

Instantly share code, notes, and snippets.

View HugoSay's full-sized avatar
:octocat:

Hugo Saynac HugoSay

:octocat:
View GitHub Profile
@HugoSay
HugoSay / SingleValueDecoding+DecodeIfPresent.swift
Last active March 17, 2021 10:12
SingleValueDecoding+DecodeIfPresent.swift
extension SingleValueDecodingContainer {
func decodeIfPresent<T>(_ type: T.Type) -> T? where T : Decodable {
print(type)
return try? decode(type)
}
}
struct MonitorStatus: Decodable {
@HugoSay
HugoSay / RemoteConfigPropertyWrapper.swift
Created December 3, 2020 13:04
Property wrapper for firebase remote config
//
// FCRemoteConfig.swift
// Brut
//
// Created by Hugo Saynac on 25/11/2020.
//
import FirebaseRemoteConfig
private let remoteConfigDecoder = JSONDecoder()
@propertyWrapper struct FCRemoteConfig<Value: Decodable> {
@HugoSay
HugoSay / HiddenNavigationLink.swift
Last active December 21, 2020 10:54
Hidden Navigation Link
@HugoSay
HugoSay / BasicSwiftUIForm.swift
Created September 25, 2020 05:03
Basic swiftUI editable profile using EditMode environment var
import SwiftUI
import MapKit
struct Profile {
var firstName: String
var lastName: String
var city: String
}
struct BasicEditableProfileView: View {
@HugoSay
HugoSay / UserDefaultWrapper.swift
Last active December 11, 2020 13:57
using a property wrapper for user defaults
//
// UserDefaultStored.swift
// SwiftUICourse
//
// Created by Hugo Saynac on 25/06/2020.
//
import Foundation
@propertyWrapper
@HugoSay
HugoSay / image with exif from UIImagePickerControllerDelegate.swift
Last active May 17, 2021 15:30
get an UIImage and a file containing the exif of the selected image.
static public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) -> (image: UIImage, url: URL)? {
guard let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else { return nil }
var url: URL?
if #available(iOS 11.0, *) {
url = info[.imageURL] as? URL
} else {
url = info[.referenceURL] as? URL
}
@HugoSay
HugoSay / callCalcultatedVars.swift
Created July 25, 2018 15:05
calls all calculated variables from a class for unit tests
//: [Previous](@previous)
import Foundation
class Foo {
@objc static var prop1: String? {
print("accessed prop1")
return "Hello I am prop1!" }
@objc static var prop2: String? {
print("accessed prop2")