swift- mutating

struct Stack<Element> {

    var items = [Element]()

    

    func push(_ item:Element){

        self.items.append(item)

    }

    

    mutating func pop() -> Element{

        return self.items.removeLast()

    }

}

 

Cannot use mutating member on immutable value: 'self' is immutable

Mark method 'mutating' to make 'self' mutable

 

 

protocol Response {

    var _metrics: AnyObject? { get set }

    func add(_ metrics: AnyObject?)

}

 

extension Response {

    func add(_ metrics: AnyObject?) {

        _metrics = metrics

    }

}

 

Cannot assign to property: 'self' is immutable

Mark method 'mutating' to make 'self' mutable

posted @ 2018-09-14 19:46  zzfx  阅读(426)  评论(0编辑  收藏  举报