How do I override observeValue?

I am trying to listen to changes in my UITableViewCell-instance and I would like to use observeValue for this so I would like to override this method. I have tried the following in my cell class:

open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        let obj = object as AnyObject?
        Loggly.log("TextFieldCell.observeValue() UIContentSizeCategoryDidChangeNotification-triggered")
    }

Only when I try this then I am getting the following compiler errors:

                     Reference: /Users/x/Development/Compilers/10.0.0.2398/Toffee SDKs/iOS 12.2 Simulator/CloudKit.fx
                     Reference: /Users/x/Development/Compilers/10.0.0.2398/Toffee SDKs/iOS 12.2 Simulator/QuartzCore.fx
E:                   Unknown type "UnsafeMutableRawPointer" [/Users/x/Development/Projects/x/x/version-3/config-app/x/Views/TextFieldCell.swift (77)]
                  <- Phase Resolving Bodies finished, took 1.6716s.
                  -> Phase Checking Members started.
E:                   Cannot find a suitable method in the base class to override with signature "func observeValue(forKeyPath keyPath: String?, of object: Any?, # change: Swift.Dictionary<NSKeyValueChangeKey,Any>?, # context: Error)" [/Users/x/Development/Projects/x/x/version-3/config-app/x/Views/TextFieldCell.swift (77)]
N:                   Possible match: func observeValue(forKeyPath NSString?, of id?, # NSDictionary<NSString!,id!>!, # UnsafePointer<Void>) [/Users/x/Development/Projects/x/x/version-3/config-app/x/Views/TextFieldCell.swift (77)]
                  <- Phase Checking Members finished, took 0.1065s.
                  -> Phase Generating Helper Types started.

How can I find the right way to override this function in Silver/Swift?

If I try to the following override I am getting an internal error in the compiler:

open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutablePointer?) {

The error:

E:                 expected, got < [/Users/x/Development/Projects/x/x/version-3/config-app/x/Views/TextFieldCell.swift (77)]
E:                Internal error: Error parsing file "/Users/x/Development/Projects/x/matrix/version-3/config-app/x/Views/TextFieldCell.swift" Object reference not set to an instance of an object
                  Reference: /Users/x/Development/Compilers/10.0.0.2398/Toffee SDKs/iOS 12.2 Simulator/CoreFoundation.fx (implicit)
E:                Internal error: System.NullReferenceException: Object reference not set to an instance of an object

Thanks, logged as bugs://82455 - for the weird error

1 Like

Thanks, logged as bugs://82456 - to support UnsafeMutableRawPointer

1 Like

Thanks, logged as bugs://82459 - for the actual overload issue

1 Like

It seems we don’t currently define UnsafeMutableRawPointer. if I change it to UnsafeMutablePointer, I get an even weirder error:

import UIKit

printf(“The magic happens here.”)

// E1 expected, got <

. The actual sig it wants is

open override func observeValue(forKeyPath keyPath: NSString?, of object: id?, change: NSDictionary<NSString!,id!>, context: UnsafePointer<Void>) {

but that too fails :(.

bugs://82455 got closed with status fixed.

bugs://82459 got closed with status fixed.

I can confirm I can compile this code now. Not sure, if it actually will get triggered yet. That’s my next step

bugs://82456 got closed with status fixed.

Great thank you!