Skip to content

Instantly share code, notes, and snippets.

View rockbruno's full-sized avatar

Bruno Rocha rockbruno

View GitHub Profile
@rockbruno
rockbruno / AccountKitForceLocalization.rb
Created July 13, 2017 13:22
iOS Account Kit script to force localization
# Bruno Rocha
# Add this file to your {SRCROOT}/bin, change ptProj to your desired locale
# and then add a Run Script at Xcode with this:
# ruby $SRCROOT/bin/AccountKitForceLocalization.rb
require 'find'
require 'uri'
require 'fileutils'
$scriptPath = File.dirname(__FILE__)
@rockbruno
rockbruno / UIButton+DualLabel.swift
Last active September 7, 2018 06:30
"Native" Dual Label UIButton
extension UIButton {
/// Sets an UIButton's left and right title separated by invisible spaces, to give the impression of having two labels
/// without losing native UIButton properties, such as animations that come with the .system button type.
/// Requires tintColor to match the button's title color.
func setDualTitle(left: String, right: String, horizontalMargin: CGFloat = 8) {
let columnCount = (UIScreen.main.bounds.width - (horizontalMargin * 2)) * 0.2
let columns = String(repeating: "|", count: Int(columnCount))
let attributedString = NSMutableAttributedString(string: left, attributes: [.foregroundColor: tintColor])
attributedString.append(NSAttributedString(string: columns, attributes: [.foregroundColor: UIColor.clear]))
attributedString.append(NSAttributedString(string: right, attributes: [.foregroundColor: tintColor]))
final class MyViewController: UIViewController {
private let myButton: UIButton = {
//
}()
 
private let myView: UIView = {
//
}()
 
//Mais umas 10 views aqui...
final class MyViewController: UIViewController {
   
let myView = MyView()
 
override func viewDidLoad() {
super.viewDidLoad()
setupMyView()
}
 
private func setupMyView() {
final class MyViewController: UIViewController {
override func loadView() {
let myView = MyView()
myView.delegate = self
view = myView
}
override func viewDidLoad() {
super.viewDidLoad()
print(view) // Uma instância de 'MyView'!
var myView: MyView {
return view as! MyView
}
/// The HasCustomView protocol defines a customView property for UIViewControllers to be used in exchange of the regular view property.
/// In order for this to work, you have to provide a custom view to your UIViewController at the loadView() method.
public protocol HasCustomView {
associatedtype CustomView: UIView
}
extension HasCustomView where Self: UIViewController {
/// The UIViewController's custom view.
public var customView: CustomView {
guard let customView = view as? CustomView else {
final class MyViewController: UIViewController, HasCustomView {
typealias CustomView = MyView
override func loadView() {
let customView = CustomView()
customView.delegate = self
view = customView
}
override func viewDidLoad() {
class CustomViewController<CustomView: UIView>: UIViewController {
var customView: CustomView {
return view as! CustomView
}
override func loadView() {
view = CustomView()
}
}
@rockbruno
rockbruno / DerivedConformanceCaseIterable+first.cpp
Last active September 21, 2018 19:09
CaseIterable + first property
ValueDecl *DerivedConformance::deriveCaseIterable(ValueDecl *requirement) {
// Conformance can't be synthesized in an extension.
if (checkAndDiagnoseDisallowedContext(requirement))
return nullptr;
// Check that we can actually derive CaseIterable for this type.
if (!canDeriveConformance(Nominal))
return nullptr;
Type returnTy;