调用这行代码时,我得到一个错误的访问(objc_msgsend):
self.currentGameTeam = nil;
Run Code Online (Sandbox Code Playgroud)
其中"currentGameTeam"在接口中为名为"MCState"的类定义为:
MNAvailableTeamContext *currentGameTeam;
Run Code Online (Sandbox Code Playgroud)
我为它合成了一个属性:
@property (retain) MNAvailableTeamContext *currentGameTeam;
Run Code Online (Sandbox Code Playgroud)
设置NSZombieEnabled后,控制台显示:
*** -[MNAvailableTeamContext release]: message sent to deallocated instance 0x5b3eba0
Run Code Online (Sandbox Code Playgroud)
调试器跟踪显示它来自合成的setter代码:
#3 0x0001fa96 in -[MCState setCurrentGameTeam:] at MCState.m:44
Run Code Online (Sandbox Code Playgroud)
我已经看了几个其他问题和线程,我找不到适用于我的案例的答案.我不明白为什么如果我合成了属性并且我将它设置为nil会有一个糟糕的访问.特别奇怪的是MCState中至少有3个其他属性的定义和使用方式与currentGameTeam完全相同,唯一的区别是它们是不同的类型:
MNUserContext *storedUser;
MNActiveGameContext *storedGame;
MNAvailableUserContext *storedGameUser;
MNAvailableTeamContext *storedGameTeam;
Run Code Online (Sandbox Code Playgroud)
和
@property (retain) MNUserContext *currentUser;
@property (retain) MNActiveGameContext *currentGame;
@property (retain) MNAvailableUserContext *currentGameUser;
@property (retain) MNAvailableTeamContext *currentGameTeam;
Run Code Online (Sandbox Code Playgroud)
和
@synthesize currentUser;
@synthesize currentGame;
@synthesize currentGameUser;
@synthesize currentGameTeam;
Run Code Online (Sandbox Code Playgroud)
最后
self.currentUser = userContext;
self.currentGame = nil;
self.currentGameUser = nil;
self.currentGameTeam = nil; // Error …Run Code Online (Sandbox Code Playgroud)