Exploring the implementation of a CSS selector traversal technique in Swift.
Here's what I have so far:
var CLASSNAME_HANDLE: UInt8 = 0
extension UIView {
@IBInspectable var className: String {
get {
//code to get className
}
set {
//code to set className
}
}
func getViewsByClass(cls: String) -> Array<UIView>{
//code to get views by class
}
func selectViews(filter:(UIView) -> Bool) -> Array<UIView>{
//code for selecting views
}
}
extension Array {
//code for forEach function
}
Now, I am able to include a className property in the interface builder like this: https://i.sstatic.net/N3HiU.png
Everything seems to be functioning correctly, but I believe there is room for performance improvement.
Q: How can I optimize this code? Is there a more efficient way to iterate through subviews and return a filtered subset?
I welcome any suggestions or advice :)