1
我想用一個撤消管理器測試一些代碼,但顯然,撤消的時候在同一個運行循環中運行時分組。我試圖關閉groupsByEvent,但它不能按預期工作。單元測試與NSUndoManager,Runloop - Obj-C
- (NSString *)article
{
return _article == nil ? @"no article" : _article;
}
- (void)setarticle:(NSString *)article
{
if (_undoManager)
{
[(ModelGraph *)[_undoManager prepareWithInvocationTarget:self] setarticle:self.article];
[_undoManager setActionarticle:@"undo set article"];
}
NSCharacterSet *charactersToRemove = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
article = [[article componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@""];
_article = article;
}
,並在我的測試,我有:
undoManager = [[NSUndoManager alloc] init];
myObject.undoManager = undoManager;
[myObject setArticle:@"Article 1"];
[myObject setArticle:@"Article 2"];
[myObject setArticle:@"Article 3"];
[myObject setArticle:@"Article 4"];
[undoManager undo];
NSLog(@"myObject.article: %@", [myObject article]); //prints noarticle
但代碼運行時,我總是回來:「沒有了」 - 當撤消發生時,它總是運行所有撤消的背...因爲它們是在同一個循環中添加的。
我只想測試我的撤消是否正在進行測試......和想法?
也許強迫運行循環在每次更改後觸發?更改運行循環模式?
任何幫助歡迎。
謝謝,克里斯