Skip to content

Instantly share code, notes, and snippets.

View AliSoftware's full-sized avatar

Olivier Halligon AliSoftware

View GitHub Profile
@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 / 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 / JSON-Rounding-Behavior.swift
Created August 21, 2018 17:29
JSON Rounding Behavior
func json(from dict: [String: Any]) -> String {
let jsonData = try! JSONSerialization.data(withJSONObject: dict, options: [])
let str = String(data: jsonData, encoding: .utf8)!
return str
}
struct Product {
var price: Double
var quantity: Int
//#! Swift 5
import Foundation
import AppKit
////////////////////////////////////////////////////////////////////
//: ## Type Definition
struct AttrString {
let attributedString: NSAttributedString
@AliSoftware
AliSoftware / FailableDecode.swift
Last active January 24, 2019 14:15
Decode an array of objects, allowing some of the items to fail without stopping the decoding of the rest
import Foundation
//: ## Option 1: A Failable type for each item
//: In practice, it's very similar to the concept of the "Result" type that you see in most code bases (and that will be integrated in Swift 5), so if you already have a Result type, you might just want to use it instead, but if not, this is a super-simplification of it
enum Failable<T>: CustomStringConvertible {
case success(T)
case failure(Error)
var description: String {
@AliSoftware
AliSoftware / lint_snippets_in_markdown.rb
Last active February 9, 2019 16:52
Runs SwiftLint on all code snippets found in a markdown file
#!/usr/bin/env ruby
require 'tmpdir'
require 'open3'
# The first parameter is supposed to be the path to the markdown file
input_file = ARGV.first
config_file = ARGV[1] || '.swiftlint.yml'
config_param = File.exist?(config_file) ? " --config #{File.realpath(config_file)}" : ''
@AliSoftware
AliSoftware / CopyLabel.swift
Last active June 20, 2020 11:42
An UILabel subclass which allows you to show the "copy" MenuController item to copy its content to the pasteboard
import UIKit
class CopyLabel : UILabel {
// MARK: Setup
override init(frame: CGRect) {
super.init(frame: frame)
configureMenu()
}
@AliSoftware
AliSoftware / JSONDecoder+Nested.swift
Created January 24, 2019 14:28
Techniques to decode Decodable types that are nested under intermediate keys in a JSON
import Foundation
let json = """
{
"data": {
"items": [
{ "name": "Alice" },
{ "name": "Bob" },
{ "name": "Claudia" }
]
@AliSoftware
AliSoftware / Mirror+DebugDescription.swift
Created January 24, 2019 21:46
Some convenience methods using Mirror to build a nice custom debugDescription easily
extension Mirror {
/// Use this to help you implement a custom debugDescription listing all properties of your instances
///
/// - Parameters:
/// - subject: The instance for which to return the description.
///
/// Example usage:
///
/// extension MyType: CustomDebugStringConvertible {
@AliSoftware
AliSoftware / Dangerfile-build_settings.rb
Last active February 14, 2019 14:27
Dangerfile Rules
#######################################
# Check that some Build Settings (those defined by VERSION_SETTINGS below) are set on the right level (target/project)
#######################################
VERSION_SETTINGS = %w(GLOBAL_APP_VERSION GLOBAL_APP_BUILD_VERSION)
require 'xcodeproj'
project = Xcodeproj::Project.open('YOUR_PROJECT_NAME.xcodeproj')
target = project.targets.find("YOUR_TARGET_NAME").first
target.build_configurations.each do |bc|
## Don't allow some build settings at target level (but only at project level)