ios – App crashes with EXC_BREAKPOINT on assigning border coloration of UICollectionViewCell

[ad_1]

I’ve code that flashes the border of a cell in a group view by altering its coloration at set intervals. When the flash sequence begins, the unique coloration of the cell is saved, in order that when the flash sequence is full, the colour will be restored. The crash that happens does not clarify precisely what’s incorrect, so I am left attempting to infer the issue, and what I am seeing within the debugger is not making a lot sense.

Notice that that is code that previously has been examined to work with out crashing, unsure why it is out of the blue failing now.

The error: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1831e1fd4) (The road seems in crimson and execution won’t proceed, so no this isn’t simply stopping at a breakpoint, it’s a crash.)

The code…

@interface OrderCollectionViewCell : UICollectionViewCell 

               .   .   .

@property (robust, nonatomic) NSTimer *borderTimer;
@property (nonatomic) BOOL blinkStatus;
@property (nonatomic) NSInteger blinkTimes;

               .   .   .

@implementation OrderCollectionViewCell
{
    CGColorRef normalBorder;
}

-(void)flashBorder
{
    // Save unique coloration for later restore
    normalBorder = self.bg.layer.borderColor;
    
    if(self.borderTimer) {
        [self.borderTimer invalidate];
    }
    self.borderTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(blink) userInfo:nil repeats:YES];
    
    [[NSRunLoop mainRunLoop] addTimer:self.borderTimer forMode:NSRunLoopCommonModes];
    
    self.blinkTimes = 0;
    self.blinkStatus = NO;
}


-(void)blink
{
    if (self.blinkTimes++ == 3)
    {
        // Sequence full.  Restore unique coloration
        self.bg.layer.borderColor = normalBorder;  // <-- This line crashes
        [self.borderTimer invalidate];
        self.borderTimer = nil;
        return;
    }
    
    if(self.blinkStatus == NO){
        self.bg.layer.borderColor = [UIColor whiteColor].CGColor;
        self.blinkStatus = YES;
    }else {
        self.bg.layer.borderColor = [UIColor orangeColor].CGColor;
        self.blinkStatus = NO;
    }
}

This is the place issues get bizarre. Based on the docs, CGColorRef is a struct, not an object. I set a breakpoint in flashBorder, and examine the worth of self.bg.layer.borderColor and variable normalBorder after copying the colour to it.

enter image description here

Notice that the handle of every is reported as <CGColor 0x281b6d200>, which is extra like object habits than struct habits.

When the time comes to revive the colour, the variable normalBorder now not seems to comprise legitimate coloration knowledge, because it’s merely reported as an handle (the identical handle as earlier than) however no descriptive output:

enter image description here

Does anybody know what could be inflicting this failure, or why within the debugger the CGColorRef appears to be performing like an object fairly than a struct?

[ad_2]

Leave a Reply