Skip to content

Instantly share code, notes, and snippets.

@dynamicMemberLookup
struct Template {
var template : String
private var data : [String:String]
var populatedTemplate : String { data.reduce(template) { $0.replacingOccurrences(of: "${\($1.key)}", with: $1.value) } }
init(template: String, data: [String:String] = [:]) {
self.template = template
self.data = data
}
@letatas
letatas / NibWrapped.swift
Created January 13, 2020 16:01
ReusableXibViews - NibWrapped - v2
//
// NibWrapped.swift
// ReusableXibViews
//
// Created by Matthias Lamoureux on 13/01/2020.
// Copyright © 2020 QSC. All rights reserved.
//
import UIKit
@letatas
letatas / NibWrapped.swift
Created January 13, 2020 15:46
ReusableXibViews - NibWrapped - v1
/// Property wrapper used to wrapp a view instanciated from a Nib
@propertyWrapper public struct NibWrapped<T: UIView> {
/// Initializer
///
/// - Parameter type: Type of the wrapped view
public init(_ type: T.Type) { }
/// The wrapped value
public var wrappedValue: UIView!
@letatas
letatas / MessageView.swift
Created January 13, 2020 15:01
ReusableXibViews - MessageView - v2
import UIKit
@IBDesignable class MessageViewWrapper : NibWrapperView<MessageView> { }
class MessageView: UIView {
...
@letatas
letatas / NibWrapperView.swift
Created January 13, 2020 14:41
ReusableXibViews - NibWrapperView
//
// NibWrapperView.swift
// ReusableXibViews
//
// Created by Matthias Lamoureux on 13/01/2020.
// Copyright © 2020 QSC. All rights reserved.
//
import UIKit
@letatas
letatas / UIView+Nib.swift
Created January 13, 2020 14:36
ReusableXibViews - UIView extension to load xib
//
// UIView+Nib.swift
// ReusableXibViews
//
// Created by Matthias Lamoureux on 13/01/2020.
// Copyright © 2020 QSC. All rights reserved.
//
import UIKit
@letatas
letatas / MessageView.swift
Last active January 13, 2020 15:01
ReusableXibViews - MessageView - v1
//
// MessageView.swift
// ReusableXibViews
//
// Created by Matthias Lamoureux on 13/01/2020.
// Copyright © 2020 QSC. All rights reserved.
//
import UIKit
@letatas
letatas / update-strings-file.swift
Created January 8, 2020 14:51
Second script used to update intent definition localization strings files (usage can be found here: https://stackoverflow.com/questions/52659028/xcode-10-how-to-refresh-localization-of-a-siri-shortcut-intent-definiotion-fil)
#!/usr/bin/swift
import Foundation
guard CommandLine.arguments.count == 3 else {
print("Usage:\n\t\(CommandLine.arguments[0]) <STRINGS_TO_TRANSFER_FILE> <STRING_FILE_ON_WHICH_TRANSFER_STRINGS>\n")
exit(1)
}
let source = CommandLine.arguments[1]
@letatas
letatas / update-modified-strings-file.sh
Last active January 8, 2020 14:49
First script used to update intent definition localization strings files (usage can be found here: https://stackoverflow.com/questions/52659028/xcode-10-how-to-refresh-localization-of-a-siri-shortcut-intent-definiotion-fil)
#!/bin/sh
set -e
if [[ -z "$1" ]]; then
echo "Usage:\n\t$0 <FILE>\n"
exit 1
fi
echo "👍 Processing $1"
@letatas
letatas / UIColor+DefaultColors.swift
Created September 11, 2019 12:31
UIColor extension to be used with the generated file representing the asset catalog parsed colors.
import UIKit
extension UIColor {
static func defaultColor(named name: String, default defaultColor: UIColor = .black) -> UIColor {
if #available(iOS 11, *) {
return UIColor(named: name) ?? defaultColor
}
else {
return _defaultColors[name] ?? defaultColor
}