Skip to content

Instantly share code, notes, and snippets.

View Bellaposa's full-sized avatar
🏝️
Working from home

bellaposa Bellaposa

🏝️
Working from home
View GitHub Profile
@Bellaposa
Bellaposa / TCA_README_ITA.md
Last active October 18, 2021 07:08
Composable Architecture ITA

The Composable Architecture

Composable Architecture (TCA, abbr) è una libreria per creare applicazioni in modo lineare e comprensibile, tenendo conto della composizione, dei test e dell'ergonomia. Può essere utilizzato in SwiftUI, UIKit e su qualsiasi piattaforma Apple (iOS, macOS, tvOS e watchOS).

/// 1 - Declare your custom "UITextField" that extends GenericSearchTextField and add it to storyboard
class SearchTextField: GenericSearchTextField<Person> {}
class StoryboardExampleViewController: UIViewController {
/// 2: - DEFINE OUTLET
/// When creating outlet of type `SearchTextField` XCode will return an error
/// It's important to change TextField type from `SearchTextField` to `UIView`
@IBOutlet weak var textField: UIView!
// Generate a random array of person
var persons = Person.generateRandomPerson()
override func viewDidLoad() {
super.viewDidLoad()
// create a custom Frame
let frame = CGRect(x: 150, y: 150, width: 200, height: 20)
// Pass model, frame and your custom CELL
let searchTextField = GenericSearchTextField(model: persons, frame: frame) { (person, cell) in
cell.textLabel?.text = person.name
searchTextField.singleItemHandler = { [weak self] value in
print(value)
}
@Bellaposa
Bellaposa / CellConfiguratorExample.swift
Created June 6, 2020 13:29
CellConfiguratorExample
searchTextField.cellConfigurator = { [weak self] (person, cell) in
cell.textLabel?.text = person.name
}
class Person: NSObject {
@objc let name: String
@objc let surname: String
init(name: String, surname: String) {
self.name = name
self.surname = surname
}
}
extension Array {
/// filter(operation: NSPredicate)
/// - Parameter operation: NSPredicate
/// - Returns: array filtered according to operation NSPredicate
public func filter(operation: NSPredicate) -> [Element]? {
let array = NSArray(array: self)
return array.filtered(using: operation) as? [Element]
}
}
@Bellaposa
Bellaposa / Contains.swift
Created June 5, 2020 09:35
Contains Example
infix operator ⊂
public func ⊂ <Element: Equatable, Root, Value: KeyPath<Root, Element>>(keyPath: Value, value: Element) -> Comparison<Root> {
Comparison(keyPath, .contains, value)
}
@Bellaposa
Bellaposa / duplicate_line_xcode.md
Created March 12, 2020 10:52 — forked from emotality/duplicate_line_xcode.md
Xcode - Duplicate Line key binding

Xcode line duplicate

Bind keys to duplicate lines in Xcode

  1. Open below directory in Finder with Cmnd + Shift + G
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
@Bellaposa
Bellaposa / GenericTableViewCell.swift
Last active May 25, 2019 16:27
GenericTableViewController Swift
import UIKit
class GenericTableViewCell<U>: UITableViewCell {
var item: U!
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: nil)
}