Skip to content

Instantly share code, notes, and snippets.

@4brunu
4brunu / AutoDelegateWrapper.stencil
Created February 17, 2021 15:00
Sourcery template for wrapping delegates with closures
import Foundation
{% macro swiftifyMethodName name %}{{ name | replace:"(","_" | replace:")","" | replace:":","_" | replace:"`","" | snakeToCamelCase | lowerFirstWord }}{% endmacro %}
{% for protocol in types.protocols where protocol.based.AutoDelegateWrapper or protocol|annotated:"AutoDelegateWrapper" %}
{% if type.name != "AutoDelegateWrapper" %}
class {{ protocol.name }}Wrapper: {{ protocol.name }} {
@4brunu
4brunu / AutoCodableObjc.stencil
Created February 15, 2021 12:48
Sourcery template for Codable on Objc classes
{% for type in types.all where type.based.AutoCodableObjc or type|annotated:"AutoCodableObjc" %}
// sourcery:inline:auto:{{ type.name }}.AutoCodableObjc
enum CodingKeys: String, CodingKey {
{% for variable in type.allVariables where variable.isComputed == false %}case {{variable.name}}
{% endfor %}
}
{{type.accessLevel}} required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
{% for variable in type.allVariables where variable.isComputed == false %}{{variable.name}} = try{% if variable.isOptional %}?{% endif %} container.decode({{variable.typeName}}.self, forKey: .{{variable.name}})
@propertyWrapper
open class PropertyWrapperWithOpenInit {
var _value: String
open init(wrappedValue: String) { // error: only classes and overridable class members can be declared 'open'; use 'public'
self._value = wrappedValue
}
open var wrappedValue: String {
get {
return _value
}
swagger: '2.0'
info:
description: "description"
version: 1.0.0
title: OpenAPI
tags:
- name: person
description: persons
paths:
/person:
swagger: '2.0'
info:
description: "description"
version: 1.0.0
title: OpenAPI
tags:
- name: person
description: persons
paths:
/person:
components:
schemas:
EventMotive:
additionalProperties: false
properties:
eventType:
$ref: '#/components/schemas/MotivesCategory'
id:
format: int32
type: integer
@4brunu
4brunu / check_static_library_bitcode_support.txt
Created March 10, 2017 11:29
Check if a static library supports bitcode
otool -l path/to/libxpto.a | grep bitcode | wc -l
OUTPUT:
0 - No bitcode support
>1 - Bitcode support
@4brunu
4brunu / SampleViewController.swift
Created January 20, 2017 15:17 — forked from JaviSoto/SampleViewController.swift
Init based Storyboard View Controller Instantiation
final class SampleViewController: StoryboardBackedViewController {
// Unfortunately this must be an IUO var, so that we can set the value after super.init
private var member: Foo!
// Proper dependency injection in a storyboard backed VC!
init(foo: Foo) {
super.init(storyboardIdentifier: "SampleViewControllerIdentifier")
// We have to set the members *after* calling super.init, since it changes the instance of `self`.
self.member = foo
@4brunu
4brunu / ButtonProblemSample.swift
Last active January 11, 2017 14:11
Button with gradient and round courners doesn't show text
import UIKit
extension UIButton {
func applyBackgroundGradientStyle() {
roundCorners()
applyGradient()
self.setTitleColor(UIColor.white, for: .normal)
}
@4brunu
4brunu / ProtocolExtensionsSample.swift
Last active January 11, 2017 14:05
Swift - Protocol extensions
//https://speakerdeck.com/realm/natasha-murashev-practical-protocol-oriented-programming?slide=19
import UIKit
protocol Shakeable {
}
extension Shakeable where Self: UIView {
func shake() {
print("shake")
}