0

I am writing an app that communicates with a Bluetooth LE device and have a singleton that handles the connection. I want to store data values from the bluetooth device in an array for processing later on, and have the data values outputted to the console via NSlog fine. However, when I take the same value I output via NSLog and add it into an NSMutableArray, it gets added twice and I am not sure why.

Here is my code that prints to NSLog as well as store the value.

if (flags & 0x10) {
    while (reportData2 < reportDataEnd2) {
        int r2rint = CFSwapInt16LittleToHost(*(uint16_t*) reportData2);
        NSLog(@"%i", r2rint);
        self.rrInt = [NSString stringWithFormat:@"%d", r2rint];
        // record if selected
        if(recording_)
        {
            [rrValues_ addObject:self.rrInt];

        }
        reportData2 += 2;
    }

The above code looks for the 0x10 flag and if its there, it takes that bit and anything else until the end of it and prints it out to the screen. If the recording_ boolean value has been enabled, then it is to store the value in the array. This all works fine but the self.rrInt gets added to my mutablearray twice! I know this because adding an NSLog to print the count of my array each time an object gets added, it goes up by 2 each time.

Any thoughts would be greatly appreciated!

skeg0
  • 187
  • 1
  • 1
  • 10
  • in general.. networking activity is very unpredictable.. things may happen once or twice or 10 times or 0 times sometimes.. that's why when you write networking code.. you will have to take networking's unpredictable state into account.. one way to deal with this is to use a finite state machine and double check the state every time you want to take an action – abbood Apr 17 '13 at 11:25
  • also in general when dealing with real time apps (most networking apps are).. an NSLog operation can be too expensive to record real time info.. you are better off using asserts or storing all your log values into a variable.. and dumping that value when the app exists – abbood Apr 17 '13 at 11:28

0 Answers0