Accessing a value of a class's variable from another - objective-c

前端 未结 2 691
别那么骄傲
别那么骄傲 2021-01-15 11:26

This is probably a silly question but I\'m having a hard time trying to solve it. The thing is that a have a class that implements a counter and at the end of it procedures

2条回答
  •  心在旅途
    2021-01-15 12:17

    In your header file you declare your iVar as

    {
        int movesCounter;
    }
    

    but you synthesize the property with

    @synthesize movesCounter = _movesCounter; // note the underscore
    

    so the movesCounter iVar does not get connected to the movesCounter property. If you are updating just movesCounter instead of self.movesCounter or _movesCounter then external classes will not be able to see these changes.

提交回复
热议问题