How can I make a weak protocol reference in 'pure' Swift (without @objc)
You need to declare the type of the protocol as AnyObject
.
protocol ProtocolNameDelegate: AnyObject {
// Protocol stuff goes here
}
class SomeClass {
weak var delegate: ProtocolNameDelegate?
}
Using AnyObject
you say that only classes can conform to this protocol, whereas structs or enums can't.
How to add default implementation using generic protocol extension?
Maybe this would be simpler.
extension Comparable {
func limit(from minValue: Self, to maxValue: Self) -> Self {
return Swift.max(Swift.min(self, maxValue), minValue)
}
}
Related Topics
How to Get Data to Return from Nsurlsessiondatatask in Swift
Auto Height Does Not Work in UIview in Swift 3
Preparing for Swift 4 - Unsafemutablepointer Migration to Unsafemutablebufferpointer
Expose an Interface of a Class Loaded from a Framework at Runtime
Loading Many UIimages from Disk Blocks Main Thread
How to Get User Nearby My Location in Geofire,Firebase
Error: Missing Return in a Closure Expected to Return 'Uiviewcontroller' (Xcode, Swift, iOS 13)
Downloading PDF Using Nsurlsession (Http Post) with Parameters
Post Urlrequest Doesn't Work in Swift 4
How to Make Text Appear in Centre of The Image
Performance Issue with Swiftui List
Double Variable in Mkmapitem Array
How to Get Buffer from Avaudioengine's Installtap at High Frequency
Error Is Value of Type 'Authdataresult' Has No Member 'Uid'
How to Calculate a Distance Between Two Anchorentities
Calling Closure Inside Closure