Text Size
Friday, April 18, 2014

IOS and LAMP Web Developer Blog by Mike Zriel

IOS Xcode

IOS Xcode

Last Updated on Wednesday, 12 March 2014 08:50

How to add regular expressions regex to xcode project

BY: Mike Zriel

How to add regular expressions regex for short to an xcode project.

  1. Download RegexKitLite from RegExLite.
  2. Uncompress files and drag & drop RegexKitLite.h and RegeKitLike.m to Xcode Project.
  3. Disable the ARC for the RegexKitLite by adding a flag:
    1. Project -> {YOUR Target} -> on the Tab the "Build Phases" and open the "Compile Sources" and add for "RegexKitLite.m" the flag "-fno-objc-arc".
  4. Add in the Tab: "Build Settings" -> "Linking" -> "Other Linker Flags" the "-licucore"

Enjoy!

 
IOS Xcode

IOS Xcode

Last Updated on Sunday, 29 December 2013 13:46

NSNotification How to use Notification in xcode in iOS

BY: Mike Zriel

How to use NSNotifications

  • Constant: #define kNOTIFICATION @"NotificationZriel"
  • Observer: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethodName) name:kNOTIFICATION object:nil];
  • Sender: [[NSNotificationCenter defaultCenter] postNotificationName:kNOTIFICATION object:nil];
  • Cancel: [[NSNotificationCenter defaultCenter] removeObserver:self name:kNOTIFICATION object:nil];
  • Method called: -(void) myMethodName { ... }

Detailed explanation below:

  1. First in your pch file, look for a file usually in 'Supporting Files' Group called {project name}-info.pch

    Create a unique constant so you don't have typos like this:

    #define kNOTIFICATION @"NotificationZriel"
    
  2. Either when you init the viewController or in the ViewDidLoad add the observer, which call any method you want to when the notification gets sent from another part of the app for example when an API request has been received or cancelled.

     
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethodName) name:kNOTIFICATION object:nil];
    
  3. Anywhere in your app for example when calling an API and you want to tell the viewController for example do this:

    [[NSNotificationCenter defaultCenter] postNotificationName:kNOTIFICATION object:nil];
    

    Also make sure your remove the notification because you dealloc your view controller so you do not get memory leaks.

    -(void)dealloc {
        
        [[NSNotificationCenter defaultCenter] removeObserver:self name:kNOTIFICATION object:nil];
        
    }
    
  4. One more thing do not forget the create the method that gets called when you receive you Notification in your view controller.

    -(void) myMethodName 
    { 
      // do something when you receive the notification
    
    }
    
  5. Any questions please feel free to post below!

 
Copyright © 2014 by Mike Zriel - Zriel.com