1

I have a UITextField when user enters i'm changing the color of some text. It works fine but i got one crash report in this method.

Here is the crash report:

Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]
Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x180d92db0 __exceptionPreprocess
1  libobjc.A.dylib                0x1803f7f80 objc_exception_throw
2  CoreFoundation                 0x180c7b77c -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]
3  CoreFoundation                 0x180c7b614 +[NSDictionary dictionaryWithObjects:forKeys:count:]

Below is my code for reference

-(NSMutableAttributedString *)suggestionAtributeString:(NSString *)suggestionString
{
if ([suggestionString length] == 0) {
    return nil;
}

NSString *searchString = stringByTrimmingCharactersInSet(_suggestionString, [NSCharacterSet whitespaceAndNewlineCharacterSet]);

NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:suggestionString];

NSRange suggestionRange2 = NSMakeRange(0, [suggestionString length]);

[attributedString setAttributes:@{
                                  NSForegroundColorAttributeName:suggestionColor2,
                                  NSFontAttributeName:_suggestionFont2
                                  }
                          range:suggestionRange2];

NSRange suggestionRange1 = [suggestionString rangeOfString:searchString options:NSCaseInsensitiveSearch];

[attributedString setAttributes:@{
                                  NSForegroundColorAttributeName:suggestionColor1,
                                  NSFontAttributeName:_suggestionFont1
                                  }
                          range:suggestionRange1];

   return attributedString;
}
  • 2
    Is `_suggestionFont1`, `_suggestionFont2`, `suggestionColor1`or `suggestionColor2` nil? – Larme Jul 14 '16 at 09:13
  • No all contains Value. –  Jul 18 '16 at 12:17
  • You got on report crash only? Do you have the iOS version/device specificity? Could for instance a font that is not loaded on that version that is causing the issue. – Larme Jul 18 '16 at 12:28

0 Answers0