简体   繁体   中英

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.

断点

调用堆栈

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.

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.

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".

在此输入图像描述

  1. Now select click "Edit Breakpoint"

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

在此输入图像描述

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

在此输入图像描述

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.

If it's not that you've set up a breakpoint - it could be related to calling methods within init. unsafe calls to self

Also see my notes about font caching and loading .

I had this problem as well, and solved it without changing my breakpoint settings. In my case, the problem was that my app had a framework whose info.plist file listed a provided font that was also listed as a provided font by the app itself (in the Fonts provided by application ). Removing the duplicate fixed this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM