Currently, when implementing delegates in Swift for classes that interact with Objective-C, delegates often need to inherit from NSObject and be marked with @objc. This requirement adds boilerplate and limits flexibility, especially when designing Swift-first APIs. This proposal suggests allowing delegates to conform to AnyObject instead, providing more flexibility and aligning with Swift conventions.
Details:
Current Limitation: Delegates must inherit from NSObject and be annotated with @objc to work with Objective-C interoperability.
Proposed Solution: Extend interoperability to delegates conforming to AnyObject, maintaining compatibility with Objective-C while embracing Swift conventions.
Benefits:
Simplifies API design by reducing boilerplate (@objc and NSObject inheritance).
Enables better alignment with Swift's type system and safety features.
Allow clients not expose strings paths inside the binary (that happens if you have to inherit from NSObject)
https://github.com/RevenueCat/purchases-ios/blob/dbcfe0ceb55879c98d7069c2c788af90b76b27d7/Sources/Purchasing/Purchases/PurchasesDelegate.swift#L24
Currently, when implementing delegates in Swift for classes that interact with Objective-C, delegates often need to inherit from NSObject and be marked with @objc. This requirement adds boilerplate and limits flexibility, especially when designing Swift-first APIs. This proposal suggests allowing delegates to conform to AnyObject instead, providing more flexibility and aligning with Swift conventions.
Details:
Benefits: Simplifies API design by reducing boilerplate (@objc and NSObject inheritance). Enables better alignment with Swift's type system and safety features. Allow clients not expose strings paths inside the binary (that happens if you have to inherit from NSObject)