1

I have the following code that keeps crashing and can't find why.

@property (nonatomic)NSUInteger numberOfShapes;
@property (strong, nonatomic)NSString *shapeInCard;
@property (strong, nonatomic)UIColor *colorOfShape;
@property (nonatomic)float shadeOfColor;enter code here

- (NSAttributedString *) contents
{
    NSMutableAttributedString *cardContents = [[NSMutableAttributedString alloc] initWithString:@""];
    UIColor *shapeColor = [self.colorOfShape colorWithAlphaComponent:self.shadeOfColor];
    NSAttributedString * shapeToUse = [[NSAttributedString alloc] initWithString:self.shapeInCard attributes:@{NSBackgroundColorAttributeName:shapeColor}]; <-------
    for (int i=0; i<self.numberOfShapes; i++) {
        [cardContents appendAttributedString:shapeToUse]; <------
        if(i < self.numberOfShapes-1) {
            [cardContents appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
        }
    }
    return cardContents;
}

The properties are set by another method.

I keep getting this error -[__NSCFNumber length]: unrecognized selector sent to instance 0x8b54fe0 on the lines marked with <--------. and I can't find the reason. I have managed to get by the fist marked line if I eliminate the attributes section only to crash at the second line.

Can someone help?

Thanks in advance.

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
gariva
  • 45
  • 4
  • 1
    `self.shapeInCard` is `NSString` or `NSNumber`? Make sure that it is `NSString`, if not that might be the issue – Akhilrajtr Apr 01 '14 at 03:42
  • what is the type of self.shapeInCard – Rose Apr 01 '14 at 04:21
  • self.shapeInCard is not a String or it does not have a length method. you should check self.shapeInCard with NSLog – Sunny Shah Apr 01 '14 at 04:30
  • 1
    The problem seems to be in the part where you initialize your properties. Could you please add the code where you are do this? – GoGreen Apr 01 '14 at 05:04
  • @Sunny shah Thanks for your answers. although self.shapeInCard is declared as a NSString al the way back I did NSlog'd it and found it also crashes there....So, there is something wrong there.... I will continue to check that later today.. Thanks all for your suggestions. – gariva Apr 01 '14 at 14:51

0 Answers0