- Open below directory in Finder with Cmnd + Shift + G
/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/
import UIKit | |
class GenericTableViewCell<U>: UITableViewCell { | |
var item: U! | |
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | |
super.init(style: .subtitle, reuseIdentifier: nil) | |
} | |
infix operator ⊂ | |
public func ⊂ <Element: Equatable, Root, Value: KeyPath<Root, Element>>(keyPath: Value, value: Element) -> Comparison<Root> { | |
Comparison(keyPath, .contains, value) | |
} |
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] | |
} | |
} |
class Person: NSObject { | |
@objc let name: String | |
@objc let surname: String | |
init(name: String, surname: String) { | |
self.name = name | |
self.surname = surname | |
} | |
} |
searchTextField.cellConfigurator = { [weak self] (person, cell) in | |
cell.textLabel?.text = person.name | |
} |
searchTextField.singleItemHandler = { [weak self] value in | |
print(value) | |
} |
// 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 |
/// 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! |
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).