Skip to content

Instantly share code, notes, and snippets.

View AliSoftware's full-sized avatar

Olivier Halligon AliSoftware

View GitHub Profile
@AliSoftware
AliSoftware / Bindings.swift
Last active April 24, 2024 01:10
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
@AliSoftware
AliSoftware / struct_vs_inheritance.swift
Last active March 27, 2024 11:57
Swift, Struct & Inheritance: How to balance the will of using Struct & Value Types and the need for Inheritance?
// #!Swift-1.1
import Foundation
// MARK: - (1) classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer
// http://realm.io/news/andy-matuschak-controlling-complexity/
@AliSoftware
AliSoftware / Demo.swift
Last active October 31, 2023 12:25
NestableCodingKey: Nice way to define nested coding keys for properties
struct Contact: Decodable, CustomStringConvertible {
var id: String
@NestedKey
var firstname: String
@NestedKey
var lastname: String
@NestedKey
var address: String
enum CodingKeys: String, NestableCodingKey {
@AliSoftware
AliSoftware / launch_ipa.sh
Last active August 4, 2023 00:13
Script to install & launch an iOS build (for iphonesimulator platform) into an iOS Simulator. Especially useful for Fabric needing a first launch to upload
#!/bin/bash
#->Usage: launch_ipa.sh <PATH.app> [DEVICE_TYPE] [IOS_RUNTIME]
#->
#-> Create a new simulator, install the app in it, launch it, wait 20s then kill it.
#-> The main purpose of this script is to just launch an app and let the applicationDidFinishLaunching… callback be called
#->
#-> - [DEVICE_TYPE] the model of simulator to use. See `xcrun simctl list devicetypes` for the full list. Defaults to 'iPhone-6s'
#-> Note: You just need to provide the last part of the full device ID from
#-> com.apple.CoreSimulator.SimDeviceType.<DEVICE_TYPE>
@AliSoftware
AliSoftware / Image+Outline-CIFilter.swift
Created May 26, 2023 16:01
A demo of applying CIFilters to Swift Images, trying to apply a glow effect
import SwiftUI
import UIKit
import CoreImage
import PlaygroundSupport
extension CIImage {
convenience init(_ uiImage: UIImage) {
if let cgImage = uiImage.cgImage {
self.init(cgImage: cgImage)
@AliSoftware
AliSoftware / Coordinators-v2.swift
Last active May 4, 2023 12:26
Our implementation of the Coordinators pattern — V2, more strict than V1
// Coordinator.swift
import Foundation
public protocol Coordinator: class {
var components: CoordinatorComponents { get }
/// Set up here everything that needs to happen just before the Coordinator is presented
///
/// - Parameter modalSetup: A parameter you can use to customize the default mainViewController's
@AliSoftware
AliSoftware / Coordinator.swift
Last active July 10, 2022 14:32
Coordinators & StateMachine - Concept
struct Coordinator {
let window: UIWindow
let navCtrl: UINavigationController?
func start() {
presentWelcomeScreen()
}
private func presentWelcomeScreen() {
let vc = WelcomeScreenViewController() // Instanciate from code, XIB, Storyboard, whatever your jam is
@AliSoftware
AliSoftware / morphing.swift
Created August 3, 2017 13:07
A simple demo of doing some morphing using CAShapeLayer & UIBezierPath
import UIKit
import PlaygroundSupport
// Create a view to display the result in playground
let view = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
view.backgroundColor = .white
PlaygroundPage.current.liveView = view;
@AliSoftware
AliSoftware / git-groom
Last active December 7, 2021 15:46
Sync git working copies' trunk and develop branches and prune local and remote deleted/orphan branches
#!/bin/bash -euo pipefail
#
# Author: O.Halligon
# Jan 2021
#
# Help
if [ "${1:-}" == "-h" -o "${1:-}" == "--help" ]; then
BASENAME=${0##*/}
@AliSoftware
AliSoftware / CountedSet.swift
Last active October 23, 2021 01:36
CountedSet custom implementation in Swift
struct CountedSet<Element: Hashable> {
private var storage: [Element: Int] = [:]
}
/// Creating a CountedSet from a Dictionary or DictionaryLiteral
///
/// let example: CountedSet = ["a": 1, "b": 3, "c": 42]
extension CountedSet: ExpressibleByDictionaryLiteral {
init(dictionaryLiteral elements: (Element, Int)...) {
self.storage = Dictionary(uniqueKeysWithValues: elements)