Objective c Switch case执行两次

Objective c Switch case执行两次,objective-c,loops,switch-statement,Objective C,Loops,Switch Statement,我有以下代码:(很长) 问题是,当控制到达案例末尾时,整个块将重新执行(因此,NSLog在stdout中出现两次) 你知道为什么会这样吗? 谢谢 编辑:未桥接代码多亏了@rmaddy,我查看了堆栈跟踪 在那里,我注意到这个案件在预期的时候被执行了一次,但之前也执行了一次,与前一个案件同时执行。。。它显示缺少其break语句,因此控件继续执行。最后,请记住检查您的所有案例是否都有中断声明 再次感谢@rmaddy请显示真实代码。这里到底发生了什么(即周围的环境)。如果你重新阅读我对你之前问题的评论,

我有以下代码:(很长)

问题是,当控制到达案例末尾时,整个块将重新执行(因此,NSLog在stdout中出现两次)

你知道为什么会这样吗? 谢谢


编辑:未桥接代码

多亏了@rmaddy,我查看了堆栈跟踪

在那里,我注意到这个案件在预期的时候被执行了一次,但之前也执行了一次,与前一个案件同时执行。。。它显示缺少其
break
语句,因此控件继续执行。最后,请记住检查您的所有案例是否都有中断声明


再次感谢@rmaddy

请显示真实代码。这里到底发生了什么(即周围的环境)。如果你重新阅读我对你之前问题的评论,我特别指出,当你发布这个问题时,一定要提供更多的环境。仅仅在没有上下文的情况下发布一个
案例
语句对我们没有帮助。
案例中的大多数代码与问题无关。问题是为什么
案例
被意外调用了两次,因此案例主体无关紧要。顺便问一下,您做了哪些调试来解决这个问题?在日志语句上放置一个断点,并查看堆栈跟踪,直到它停止两次。查看什么代码路径导致它被调用两次。什么
switch
语句??没有。对不起,我把这个问题搞砸了。要更新有时你只是错过了一次休息,这会带来很多麻烦=)
//declarations (in the header) :
NSDictionary* batteryRawDict;
@property (strong, atomic, readonly) NSDictionary* batteryReport; //this dictionary is, obviously, @synthesize'd

-(BOOL) refreshGroup:(PFSystemKitGroup)group {
kern_return_t result;
switch (group) {
    case PFSKGroupGraphics: {
        val4Key("graphicReport", [self listGraphics]);
        //break;
    }
    case PFSKGroupBattery: { //to get more informations or to subscribe for events about power sources, use the IOPowerSources API
        if (!firstRunDoneForBattery) {
            batEntry = IOServiceGetMatchingService(masterPort, IOServiceMatching("IOPMPowerSource"));
            if (batEntry == 0) {
                _error = PFSKReturnComponentUnavailable;
                return false;
            }
        }
        CFMutableDictionaryRef  batProps = NULL;
        result = IORegistryEntryCreateCFProperties(batEntry, &batProps, NULL, 0);
        if (result!=kIOReturnSuccess) {
            _error = PFSKReturnIOKitCFFailure;
            _extError = result;
            return false;
        } else {
            batteryRawDict = (__bridge_transfer NSDictionary*)batProps;
            NSMutableDictionary* temp = [NSMutableDictionary.alloc init];
            if (!firstRunDoneForBattery) { //static keys
                //[temp setObject:[batteryRawDict objectForKey:@"DesignCapacity"] forKey:@"DesignedCapacity"];
                [temp setObject:[batteryRawDict objectForKey:@"DesignCycleCount9C"] forKey:@"DesignedCycleCount"];
                [temp setObject:[batteryRawDict objectForKey:@"BatterySerialNumber"] forKey:@"Serial"];
                [temp setObject:[batteryRawDict objectForKey:@"DeviceName"] forKey:@"Model"];
                [temp setObject:[batteryRawDict objectForKey:@"Manufacturer"] forKey:@"Manufacturer"];
                unsigned int manufactureDateAsInt = [[batteryRawDict objectForKey:@"ManufactureDate"] intValue];
                NSDateComponents* manufactureDateComponents = [[NSDateComponents alloc]init];
                manufactureDateComponents.year = (manufactureDateAsInt >> 9) + 1980;
                manufactureDateComponents.month = (manufactureDateAsInt >> 5) & 0xF;
                manufactureDateComponents.day = manufactureDateAsInt & 0x1F;
                [temp setObject:[[NSCalendar currentCalendar] dateFromComponents:manufactureDateComponents] forKey:@"ManufactureDate"];
                firstRunDoneForBattery = 1;
            }
            [temp setObject:[batteryRawDict objectForKey:@"BatteryInstalled"] forKey:@"isPresent"];
            [temp setObject:[batteryRawDict objectForKey:@"FullyCharged"] forKey:@"isFull"];
            [temp setObject:[batteryRawDict objectForKey:@"IsCharging"] forKey:@"isCharging"];
            [temp setObject:[batteryRawDict objectForKey:@"ExternalConnected"] forKey:@"isACConnected"];
            [temp setObject:[batteryRawDict objectForKey:@"Amperage"] forKey:@"Amperage"];
            [temp setObject:[batteryRawDict objectForKey:@"CurrentCapacity"] forKey:@"CurrentCapacity"];
            [temp setObject:[batteryRawDict objectForKey:@"MaxCapacity"] forKey:@"MaxCapacity"];
            [temp setObject:[batteryRawDict objectForKey:@"Voltage"] forKey:@"Voltage"];
            [temp setObject:[batteryRawDict objectForKey:@"CycleCount"] forKey:@"CycleCount"];
            [temp setObject:@(([[batteryRawDict objectForKey:@"MaxCapacity"] intValue] / [[batteryRawDict objectForKey:@"DesignCapacity"] intValue])*100) forKey:@"Health"]; //percentage
            [temp setObject:@([[batteryRawDict objectForKey:@"Temperature"] doubleValue] / 100) forKey:@"Temperature"];
            /*to be checked*/[temp setObject:@([[batteryRawDict objectForKey:@"Amperage"] doubleValue] / 1000 * [[batteryRawDict objectForKey:@"Voltage"] doubleValue] / 1000) forKey:@"Power"];
            NSDateComponents* differenceDate = [[NSCalendar currentCalendar] components:NSCalendarUnitDay
                                            fromDate:[temp objectForKey:@"ManufactureDate"]
                                              toDate:[NSDate date]
                                             options:0];
            [temp setObject:@([differenceDate day]) forKey:@"Age"];
            NSLog(@"--------------------------------------------------------");
            batteryReport = [temp copy];
        }
        _error = PFSKReturnSuccess;
        return true;
    }
}
_error = PFSKReturnSuccess;
return true;
}