+(UIColor *) colorFromDashSeperatedStringRepresentation: (NSString *) dashSeperatedStr
{
NSArray * components = [dashSeperatedStr componentsSeparatedByString:@"#"];
assert([components count] == 4); // Assertion failure here...
float red = [[components objectAtIndex:0] floatValue];
float green = [[components objectAtIndex:1] floatValue];
float blue = [[components objectAtIndex:2] floatValue];
float alpha = [[components objectAtIndex:3] floatValue];
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
可以看出......有四个组成部分。它们都被列为单独的属性。这是日志中的错误......
Assertion failed: ([components count] == 4), function +[CAG_Color colorFromDashSeperatedStringRepresentation:], file /Users/marc/Documents/CAG/iClassNotes/iClassNotes/iClassNotes/CAG_Color.m, line 77.
任何帮助都会非常感激!!!通过将所有控制器移植到新创建的项目中而不触及NSDocumentDirectory方法,我只能在这个新应用程序上解决此错误。我想知道这里的错误是什么!
这个解决方案允许我给出数组值,并满足断言,这被称为无数次...我的应用程序是一个文本应用程序,颜色模型使用了很多。
+(UIColor *) colorFromDashSeperatedStringRepresentation: (NSString *) dashSeperatedStr
{
NSArray * components = [dashSeperatedStr componentsSeparatedByString:@"#"];
NSLog(@"Components before assert: %@", components);
if (components == NULL)
{
NSArray *values = @[@0.000000, @0.000000, @1.000000, @0.000000];
components = values;
}
NSLog(@"Components after if: %@", components);
assert([components count] == 4);
float red = [[components objectAtIndex:0] floatValue];
float green = [[components objectAtIndex:1] floatValue];
float blue = [[components objectAtIndex:2] floatValue];
float alpha_c = [[components objectAtIndex:3] floatValue];
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha_c];
}
希望这有助于某人!