1
#import "someClass.h"

@implementation someClass

- (NSInteger *)checkWakeOnLan {
    SCDynamicStoreRef ds = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("myapp"), NULL, NULL);
    CFDictionaryRef dr = SCDynamicStoreCopyValue(ds, CFSTR("State:/IOKit/PowerManagement/CurrentSettings"));
    CFNumberRef wol=CFDictionaryGetValue(dr, CFSTR("Wake On LAN"));
    CFRelease(dr);
    CFRelease(ds);

here my problem, how to convert CFNumberRef to NSInteger, i tryed again and again, but got anytime "makes integer from pointer without cast"

    NSInteger *value = [... ?];
    return value;
}

- (IBAction)doStuff:(NSButton *)sender {
    [myBevelButton setState:[self checkWakeOnLan]]; //setState takes NSInteger
    //myBevelButton defined elsewhere, shows different icons 
}

@end   
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
Ol Sen
  • 3,163
  • 2
  • 21
  • 30

1 Answers1

3

Use this:

//assuming you want to convert wol to NSNumber and then to NSInteger

NSNumber *nsnumber = (NSNumber*)wol;
NSInteger value = [nsnumber integerValue];

*NOTE: You rarely need an NSInteger pointer. In your case you can quite easily use NSInteger. Also you need to change the method as - (NSInteger)checkWakeOnLan

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140