Question

#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   
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top