Saturday, July 15, 2017

NSNotificationCenter is Communication tools internal to your app

In App Development some time we need internal communication to pass message to one ViewController to other ViewController. As Example. I am using Google login using Firebase now login task doing AppDelegate Now i need message when login success or fail on ViewController.  Then here we can use NSNotificationCenter.

1. Create Globally define a"Special Notification Key" constant that can be broadcast. on ViewController

   let mySpecialNotificationKey = "com.arkay.specialNotificationKey" 


2. Set Observer on ViewController.
        NotificationCenter.default.addObserver(self, selector: #selector(ViewController.updateNotificationSentLabel), name: NSNotification.Name(rawValue: mySpecialNotificationKey), object: nil)

3. Create Func that can call when Notify ViewController

 func updateNotificationSentLabel(){
        btnSignIn.setTitle("Login Out",for: .normal)
    }]

4. Now Call When need. Right now i am calling from AppDelegate.

        NotificationCenter.default.post(name: Notification.Name(rawValue: mySpecialNotificationKey), object: self)


That's it.

Friday, July 14, 2017

Getting start with CocoaPods iPhone app Using XCode.

As you know without lib it's to difficult to completed project. In Android we use Gradle  as Dependency manager but in Swift and Objective-c it's CocoaPods is Dependency Manager. This tutorial will explain how to getting start with CocoaPods on XCode.

1. Create iPhone new project using XCode.
2. Now Close this Project.
3. Execute Following command.
sudo gem install cocoapods



4.  Open Terminal and goes on your Project location.
cd ~/Desktop/CocoapodsTestApp
 
5.  Now Simple Execute following command.
pod init
 
6. Now check project location it will be generate PodFile.


7. Open that Pod File on Text Editor It will be look like below.

8. Now you can add as my POD at # Sing. Let's try add Firebase Pod There.


9.  Now Save this file. 
10. And Execute following command same as project location.
pod install



11.  its done.. Thanks..
12. Now Open xcode Proejct. Be CAREFUL when open .xcworkspace file not .xcodeproj

Thanks.