开发者

Mutable copy of a CoreFundation Reference type

开发者 https://www.devze.com 2023-03-02 05:13 出处:网络
In 开发者_如何学运维xcode4/Objective C, on Leopard: I have a CGDisplayModeRef which is as I understand it an Immutable Dictionary Reference.

In 开发者_如何学运维xcode4/Objective C, on Leopard:

I have a CGDisplayModeRef which is as I understand it an Immutable Dictionary Reference. I need to modify this so I tried to get a mutable copy like this:

 CGDisplayModeRef displayMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
 NSMutableDictionary * displayModeMutable = 
                   [((NSDictionary *)&displayMode) mutableCopy];

Strangely enough I get a dictionary containing my App delegate back! What is the correct way to do this?

By the way I want to set the refresh rate for a CRT display to 100 Hz which I know the hardware supports but Leopard thinks it does not! So I need to manually change the refresh rate in the "displayMode"


I have a CGDisplayModeRef which is as I understand it an Immutable Dictionary Reference

No I don't think so; you confuse the 10.5 function CGDisplayCurrentMode which returns CFDictionaryRef, and the 10.6 function CGDisplayModeRef. The latter is not a CFDictionaryRef.

The only thing supported using 10.6 functions is to get the list of available modes via CGDisplayCopyAllDisplayModes, choose one which suites your purpose, and set it back with CGDisplaySetDisplayMode. As a preparation for future expansion, CGDisplaySetDisplayMode accepts the options as CFDictionaryRef, but you can't use it currently.

By the way, even when you cast a CFDictionaryRef to NSDictionary, you have one too many &. A ...Ref is already a pointer, so

CFDictionaryRef a;
NSDictionary* b=(NSDictionary*)a;

should suffice. You shouldn't use (NSDictionary*)&a.

0

精彩评论

暂无评论...
验证码 换一张
取 消