I am trying to get the name of a UITextField for use in shouldChangeCharactersIn. (I am already using the .tag to hold some other data). I was trying to use this code which I converted to Swift 4:
func propertyName(_ property: Any?) -> String? {
var numIvars: UInt = 0
var key: String? = nil
let ivars: Ivar? = class_copyIvarList(type(of: self), numIvars)
for i in 0..<Int(numIvars) {
let thisIvar = ivars[i] as? Ivar
if (object_getIvar(self, thisIvar) == property) {
key = String(utf8String: ivar_getName(thisIvar))
break
}
}
free(ivars)
return key
}
Which I found here but am getting an error "Cannot convert value of type 'UInt' to expected argument type 'UnsafeMutablePointer?"
My goal is to determine which UITextField is currently selected for editing (I need to limit the max characters based on which field is being edited using shouldChangeCharactersIn).
Thanks in advance.
Update #1: I cannot compare the UITextFields to outlet property because the fields are part of a tableview and dynamically created.