iOS crash report “unexpected start state” exception?

The above crash happens when you try initializing a NSAttibutedString with html content from any other thread than the main thread. So the solution here is to make sure the above NSAttributedString initialization is always called from the main thread. DispatchQueue.main.async { let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [.documentType: NSAttributedString.DocumentType.html] let htmlString = try? NSAttributedString(data: htmlData, … Read more

Catching NSException in Swift

Here is some code, that converts NSExceptions to Swift 2 errors. Now you can use do { try ObjC.catchException { /* calls that might throw an NSException */ } } catch { print(“An error ocurred: \(error)”) } ObjC.h: #import <Foundation/Foundation.h> @interface ObjC : NSObject + (BOOL)catchException:(void(^)(void))tryBlock error:(__autoreleasing NSError **)error; @end ObjC.m #import “ObjC.h” @implementation ObjC … Read more

@try – catch block in Objective-C

All work perfectly 🙂 NSString *test = @”test”; unichar a; int index = 5; @try { a = [test characterAtIndex:index]; } @catch (NSException *exception) { NSLog(@”%@”, exception.reason); NSLog(@”Char at index %d cannot be found”, index); NSLog(@”Max index is: %lu”, [test length] – 1); } @finally { NSLog(@”Finally condition”); } Log: [__NSCFConstantString characterAtIndex:]: Range or index … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)