正確にはどのように機能しNSInvocation
ますか?良い紹介はありますか?
次のコード ( Cocoa Programming for Mac OS X, 3rd Editionから) がどのように機能するかを理解するのに特に問題がありますが、チュートリアルのサンプルとは別に概念を適用することもできます。コード:
- (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index
{
NSLog(@"adding %@ to %@", p, employees);
// Add inverse of this operation to undo stack
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] removeObjectFromEmployeesAtIndex:index];
if (![undo isUndoing])
[undo setActionName:@"Insert Person"];
// Finally, add person to the array
[employees insertObject:p atIndex:index];
}
- (void)removeObjectFromEmployeesAtIndex:(int)index
{
Person *p = [employees objectAtIndex:index];
NSLog(@"removing %@ from %@", p, employees);
// Add inverse of this operation to undo stack
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] insertObject:p
inEmployeesAtIndex:index];
if (![undo isUndoing])
[undo setActionName:@"Delete Person"];
// Finally, remove person from array
[employees removeObjectAtIndex:index];
}
私はそれがやろうとしていることを理解しています。(ところで、employees
カスタムNSArray
クラスPerson
です。)
.NET の専門家として、なじみのない Obj-C および Cocoa の概念を、ほぼ類似した .NET の概念に関連付けようとします。これは .NET のデリゲートの概念に似ていますが、型付けされていませんか?
これは本から 100% 明らかになっているわけではないので、単純な (っぽい) 例の下にある基本的な概念を理解することを目標に、実際の Cocoa/Obj-C の専門家から補足的なものを探しています。私は本当に知識を独立して適用できるようになりたいと思っています.9章までは、それを行うのに何の問題もありませんでした. でも今 ...
前もって感謝します!