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

标签 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];
}

但是,我不确定这是否是发送矩形结构的最佳方式。

最佳答案

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

关于cocoa - 使用 NSRect 信息发布 NSNotification 的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/876795/

相关文章:

iphone - 创建 3d 立方体,使用上下左右触摸移动控制旋转 iPhone, iOS

ios - Popover 通知 View ,独立于 swift 中的当前 View Controller

HTML5 桌面通知

objective-c - 强制某个类发布特定的 NSNotification?

ios - NSNotification如果数据更改

iphone - Soundtouch bpm iPhone

swift - 如何更改 NSTableHeaderCell 的字体大小

objective-c - NSWindow 失去焦点时没有收到任何通知

objective-c - Cocoa应用程序的程序流程是怎样的

Android:如果从最近的任务启动应用程序,则 Activity 正在使用旧 Intent