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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
searchTextField.singleItemHandler = { [weak self] value in | |
print(value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
searchTextField.cellConfigurator = { [weak self] (person, cell) in | |
cell.textLabel?.text = person.name | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person: NSObject { | |
@objc let name: String | |
@objc let surname: String | |
init(name: String, surname: String) { | |
self.name = name | |
self.surname = surname | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator ⊂ | |
public func ⊂ <Element: Equatable, Root, Value: KeyPath<Root, Element>>(keyPath: Value, value: Element) -> Comparison<Root> { | |
Comparison(keyPath, .contains, value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class GenericTableViewCell<U>: UITableViewCell { | |
var item: U! | |
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | |
super.init(style: .subtitle, reuseIdentifier: nil) | |
} | |