0

I have a property inside protocol and I make an extension to my class it forces me to override the set and get I want to able set and get the default

I tried to make it like the below but I get a warning "Function call causes an infinite recursion"

  var didSelectSpecificCoinClousre: didSelectHandler? {
        get {
            return self.didSelectSpecificCoinClousre
        }
        set(value) {
            self.didSelectSpecificCoinClousre = value
        }
    }

my protocol :

protocol SelectedSpecificCoinProtocol {
    
    typealias didSelectHandler = () -> (Void)?
    var didSelectSpecificCoinClousre:didSelectHandler? { get set }
    
}
Hello422
  • 27
  • 4
  • Don't put the implementation in an extension. Then you don't have to write the getters and setters, and can write a stored property instead. – Sweeper Oct 07 '22 at 13:23
  • thanks, It works. but I would appreciate an explanation why when I implement via extension I have to override get set – Hello422 Oct 07 '22 at 14:14

0 Answers0