NSRange to Range

As of Swift 4 (Xcode 9), the Swift standard library provides methods to convert between Swift string ranges (Range<String.Index>) and NSString ranges (NSRange). Example: let str = “a👿b🇩🇪c” let r1 = str.range(of: “🇩🇪”)! // String range to NSRange: let n1 = NSRange(r1, in: str) print((str as NSString).substring(with: n1)) // 🇩🇪 // NSRange back to String … Read more

UIAlertController custom font, size, color

Not sure if this is against private APIs/properties but using KVC works for me on ios8 UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@”Dont care what goes here, since we’re about to change below” message:@”” preferredStyle:UIAlertControllerStyleActionSheet]; NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@”Presenting the great… Hulk Hogan!”]; [hogan addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:50.0] range:NSMakeRange(24, 11)]; [alertVC setValue:hogan forKey:@”attributedTitle”]; UIAlertAction *button = … Read more

Location Services not working in iOS 8

I ended up solving my own problem. Apparently in iOS 8 SDK, requestAlwaysAuthorization (for background location) or requestWhenInUseAuthorization (location only when foreground) call on CLLocationManager is needed before starting location updates. There also needs to be NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key in Info.plist with a message to be displayed in the prompt. Adding these solved my … Read more