Monday, 14 September 2015

How to export a certificate.

To export a certificate from your keychain with the private key, Command-Click the certificate and choose ‘Export “Your Certificate Name”’ and choose the Personal Information Exchange format (.p12). You will be asked to enter a password to protect this file. Once you are done, anyone who has the p12 file and the password will be able to install the certificate and private key into their own keychain

Wednesday, 9 September 2015

Localization in iOS apps

CoreData Lightweight Migrations

NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil
        URL:storeURL options:options error:&error]

CoreData - SQL Debug 3 takes a value between 1 and 3; the higher the value, the more verbose the output.

Monday, 7 September 2015

Singleton Pattern

+ (instancetype)sharedInstance {
  static id _sharedInstance = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
      _sharedInstance = [[self alloc] init];
  return _sharedInstance;

Friday, 4 September 2015

Find Height of String (with Emoji support)

#import <CoreText/CoreText.h>
- (CGFloat)heightStringWithEmojis:(NSString*)str fontType:(UIFont *)uiFont ForWidth:(CGFloat)width {

// Get text
CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CFAttributedStringReplaceString (attrString, CFRangeMake(0, 0), (CFStringRef) str );
CFIndex stringLength = CFStringGetLength((CFStringRef) attrString);

// Change font
CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef) uiFont.fontName, uiFont.pointSize, NULL);
CFAttributedStringSetAttribute(attrString, CFRangeMake(0, stringLength), kCTFontAttributeName, ctFont);

// Calc the size
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);
CFRange fitRange;
CGSize frameSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, 0), NULL, CGSizeMake(width, CGFLOAT_MAX), &fitRange);


return frameSize.height + 10;


ManagedObjectContext for Core Data Operations in Background thread.

- (NSManagedObjectContext*)getNewPrivateManagedObjectContext{
    NSManagedObjectContext *privateContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    [privateContext performBlockAndWait:^{
        [privateContext setParentContext:self.managedObjectContext];
        [privateContext setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
    return privateContext ;