使用NSRect信息发布NSNotification的最佳方式?

coc*_*fan 2 cocoa notifications nsnotifications

使用NSRect信息发布通知的最佳方式是什么?

这是我目前的解决方案(使用NSStringFromRect).

- (void)postNotificationForDirtyRect:(NSRect)rect
{
    NSDictionary *userInfo = 
        [NSDictionary dictionaryWithObject: NSStringFromRect(rect) 
                                     forKey: ILDirtyRect];

    NSNotificationCenter *ncenter = [NSNotificationCenter defaultCenter];
    [ncenter postNotificationName: ILDocumentBecomeDirtyRectNotification
                           object: self 
                         userInfo: userInfo];
}
Run Code Online (Sandbox Code Playgroud)

但是,我不确定这是否是发送rect结构的最佳方法.

Mat*_*all 6

您应该使用使用类方法创建的NSValue+valueWithRect:.