Swift类型转换

时间:2015-02-27 19:47:39

标签: macos swift casting

如何将NSApplicationPresentationOptions转换为AnyObject?as在这里不起作用。
我想打电话:

func enterFullScreenMode(_ screen: NSScreen, withOptions options: [NSObject: AnyObject]?) -> Bool

我有:

let presOptions: NSApplicationPresentationOptions =
    .HideDock                  |   // Dock is entirely unavailable. Spotlight menu is disabled.
    .AutoHideMenuBar           |   // Menu Bar appears when moused to.
    .DisableAppleMenu          |   // All Apple menu items are disabled.
    .DisableProcessSwitching   |   // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
    .DisableForceQuit          |   // Cmd+Opt+Esc panel is disabled.
    .DisableSessionTermination |   // PowerKey panel and Restart/Shut Down/Log Out are disabled.
    .DisableHideApplication    |   // Application "Hide" menu item is disabled.
    .AutoHideToolbar           |
    .FullScreen

let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions: presOptions]

browserWindowController.containerView.enterFullScreenMode(NSScreen.mainScreen()!, withOptions: optionsDictionary)

这给了我最后一行的错误:

Cannot invoke 'enterFullScreenMode' with an argument list of type '(NSScreen, with Options: [String : NSApplicationPresentationOptions])'

1 个答案:

答案 0 :(得分:1)

根据documentation,相应的值为 键 NSFullScreenModeApplicationPresentationOptionsNSNumber的实例,包含无符号整数值NSApplicationPresentationOptions,因此这应该有效:

let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions : 
                         NSNumber(unsignedLong: presOptions.rawValue)]