Snippets Collections
//'weak' must not be applied to non-class-bound 'any ListNotesDelegate'; consider adding a protocol conformance that has a class bound

//Whenever we want to create a weak reference the parent of object must conform to a class like AnyObject or UILabel etc.

//Example - 1

@IBOutlet weak private var titleLbl: UILabel!  //Here UILabel is a class
  
//Example - 2

protocol ListNotesDelegate {
    func refreshNotes()
    func deleteNote(with id: UUID)
}  

var delegate: ListNotesDelegate?  //You cannot assign this as weak var 
  
//To define it as weak -

protocol ListNotesDelegate:AnyObject {//Here AnyObject is a type alias for multiple classes
    func refreshNotes()
    func deleteNote(with id: UUID)
}  

weak var delegate: ListNotesDelegate?
star

Fri Apr 12 2024 06:37:48 GMT+0000 (Coordinated Universal Time)

#swift #retailcycle

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension