With what should I replace the deprecated sizeWithFont: method?

After an hour of trial error I managed to make it work: CGSize maximumLabelSize = CGSizeMake(tableView.width, MAXFLOAT); NSStringDrawingOptions options = NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin; NSDictionary *attr = @{NSFontAttributeName: [UIFont systemFontOfSize:15]}; CGRect labelBounds = [string boundingRectWithSize:maximumLabelSize options:options attributes:attr context:nil]; Update: As Mr. T mentions in answer below : In iOS 7 and later, this method returns fractional … Read more

What does the text inside parentheses in @interface and @implementation directives mean?

Those are called Categories and allow you to add further functionality to your classes. A category allows you to add methods to an existing class—even to one for which you do not have the source. Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing. Using categories, you … Read more

Correct implementation of parent/child NSManagedObjectContext

The parent/child MOC model is a really powerful feature of Core Data. It simplifies incredibly the age-old concurrency problem we used to have to deal with. However, as you’ve stated, concurrency is not your issue. To answer your questions: Traditionally, you use the NSMainQueueConcurrencyType for the NSManagedObjectContext associated with the main thread, and NSPrivateQueueConcurrencyTypes for … Read more

Sorting NSString values as if NSInteger using NSSortDescriptor

You can do this by implementing a custom comparator block when creating your NSSortDescriptor: NSSortDescriptor *aSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@”sort” ascending:YES comparator:^(id obj1, id obj2) { if ([obj1 integerValue] > [obj2 integerValue]) { return (NSComparisonResult)NSOrderedDescending; } if ([obj1 integerValue] < [obj2 integerValue]) { return (NSComparisonResult)NSOrderedAscending; } return (NSComparisonResult)NSOrderedSame; }]; self.myList = [NSMutableArray arrayWithArray:[unsortedList sortedArrayUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]]]; See … Read more

UITextView lineSpacing causes different cursor height inbetween paragraph lines

Finally I found a solution that solve my problem. Changing the cursor height is possible by subclassing the UITextView, then overriding the caretRectForPosition:position function. For example: – (CGRect)caretRectForPosition:(UITextPosition *)position { CGRect originalRect = [super caretRectForPosition:position]; originalRect.size.height = 18.0; return originalRect; } Documentation link: https://developer.apple.com/documentation/uikit/uitextinput/1614518-caretrectforposition Update: Swift 2.x or Swift 3.x See Nate’s answer. Update: Swift … Read more

iOS 5: How to convert an Emoji to a unicode character?

Please try this : Convert Emoji to unicode NSData *data = [strEmo dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; Very easy to convert unicode to Emoji NSData *data = [strEmo dataUsingEncoding:NSUTF8StringEncoding]; NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];

Get the type of a file in Cocoa

You could use Uniform Type Identifiers. Since UTIs are organised into hierarchies, one possibility is to check whether the preferred UTI for a given file conforms to a top-level UTI, e.g. public.image for images or public.movie for movies. The Core Services framework includes functions that operate on UTIs as well as constants representing known UTIs. … Read more