Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 6.3 (and 6.2) hits breakpoint on [UIFont fontWithName: size:]

In My iOS Application im using a class (DKTheme) to keep my fonts and images in a centralised place. my implementation looks like this.

+ (instancetype)theme {
    static DKTheme *_theme = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _theme = [[DKTheme alloc] init];
    });
    return _theme;
}

- (id)init {
    self = [super init];
    if (self) {
        [self setupTheme];
    }
    return self;
}

- (void)setupTheme {
// some code here
self.smallButtonFont = [UIFont fontWithName:@"Helvetica-Bold" size:13.0f];
//some code here
}

And when i run this code in device (iPhone 5C, iOS8.3 and iOS8.2), xcode hits breakpoint on the line self.smallButtonFont = [UIFont fontWithName:@"Helvetica-Bold" size:13.0f]; if i click continue execution button, application continue running without crashing and my font property(self.smallButtonFont) is successfully initialised.

Breakpoint

Call Stack

and i noticed one more thing, i have several [UIFont fontWithName: size:]; calls and breakpoint hits only first time call.(if i comment the first one then next method call hits the break point). it is really annoying this breakpoint issue, any help would be thankful.

like image 972
Chathuranga Jayawardhana Avatar asked Apr 26 '15 06:04

Chathuranga Jayawardhana


3 Answers

You have added a breakpoint exception in Xcode and configured it to break on all exception types, C++ and Objective-C. The problem is that C++ code sometimes uses exceptions for non-exceptional situations. It may use it just as a form of flow control or returning "failure" from a function.

Unless you have a specific C++ exception that you need to debug because it's actually causing a problem, probably best to configure that breakpoint to just break on Objective-C exceptions and not C++ exceptions. The C++ exceptions can be safely ignored.

like image 109
Ken Thomases Avatar answered Nov 15 '22 03:11

Ken Thomases


This always happens when you added All Exceptions breakpoint. Here, you need to add only objective-c breakpoint. Follow these steps:

  1. Select Breakpoints debugger, right click on "All Exceptions".

enter image description here

  1. Now select click "Edit Breakpoint"

  2. Change Exception type to "Objective-c Exception"

enter image description here

like image 21
Mehul Thakkar Avatar answered Nov 15 '22 01:11

Mehul Thakkar


At first. Of course it is exception breakpoint. You can add or delete it in "Breakpoints tab". My screenshot can help you with it.

enter image description here

Reason of generation this exceptions:

You have some default fonts in iOS. If you try to generate fond with unavailable font name. You see exception like this. Maybe in your code you use some another font name. I mean not only @"Helvetica-Bold". And now you have a question: How can i now, Is font available in my OS. You can print all available fonts using this method:

- (void)fontsList
{
    NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
    NSArray *fontNames;
    NSInteger indFamily, indFont;
    for (indFamily=0; indFamily<[familyNames count]; ++indFamily) {
        NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
        fontNames = [[NSArray alloc] initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];
        for (indFont=0; indFont<[fontNames count]; ++indFont) {
            NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
        }
    }
}

Best regards. And please add some info if you still have this problem.

like image 1
Nuzhdin Vladimir Avatar answered Nov 15 '22 03:11

Nuzhdin Vladimir