Sunday, 19 June 2016

IOS COCOAPODS INSTALL & USE

Hi!

    Cocoapods is a dependancy manager of cocoa projects for Swift and Objective-C. It contain lots of projects and library to reduce your work. cocoapods comfortable for IOS, OS X, WatchOS and tvOS.  

Configuration:

        on MAC system install on the latest one is good.
OS X : OS X 10.11 or grater is good to install cocoapods. 
XCODE : XCODE version 7.3 or grater is good.
IOS : IOS 9.3 or grater.

Process To Install:

1) Open TERMINAL ((cmd+space) type terminal)
2) $ sudo gem install cocoapods  (Install cocoapods)
   Notes :  if your are using OSX EI Caption please fallow the below
2) $ sudo gem install -n /usr/local/bin cocoapods 
3) $ ******** (you have to enter your system password when ask by terminal)
4) $ pod setup (setup the pod)
  Notes : it will take some time to download and setup please be patient 

Thats all about install

How to use COCOAPODS

1) create a new project on XCODE
2) Exit from Xcode
3) Open Terminal
4) Direct and open the folder on the project
    xxxxx:~ iosdcs$  cd folder/which/contain/project 
5) $ pod init (it will initiate the pod on the project)


6) $ open -a Xcode podfile (to open the pod file on xcode to make changes)
Notes : you can edit your pod file based on your requirement to call the library



eg:

# Uncomment this line to define a global platform for your project platform :ios, '9.0'

target 'Jesus' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
pod 'Alamofire''~> 3.0'

  # Pods for Jesus

  target 'JesusTests' do
    inherit! :search_paths
pod 'Alamofire''~> 3.0'
    # Pods for testing
  end

  target 'JesusUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

7) Save and quit the xcode



8) $ pod install (to install the pod file on the project)
  it will create a pod file on your project folder

9) Go to your project directory and open the "your_project_name.xcworkspace"
   Notes : don't open "your_project_name.xcodeproj"

Notes : 

If it makes any problems like file not found and etc.., please fallow as shown on this image for setup.




Enjoy The Coding!


Sample Code :


import UIKit

import Alamofire
// Import your library




    override func viewDidLoad() {

        
        super.viewDidLoad()
        
        Alamofire.request(.GET, url_maj).responseJSON { response in
            if let JSON = response.result.value {
                let jsonObj = JSON as? NSDictionary
                let data_ = jsonObj!["data"] as! NSArray
                for item in data_ {
                    let MS04Key = item["MS04Key"]!
                    let MajorName = item["MajorName"]!
                    print("MS04Key is \(MS04Key!)")
                    print("MajorName is \(MajorName!)")
                }
            }
        }
        
    }


for POST


Alamofire.request(.POST, "http://xxxxx/xxxxx/xxxxx/get", parameters: ["xxType": "dradr","xxName": "Test Attaching","xxxcusName": "THE LIGHT","fxxolderName": "xout00001t","xxsubmitterName": "METEST"]).responseJSON { response in
            if let JSON = response.result.value {

// Your Logic
}


Thank You!


Have A Great Day..,




Tuesday, 16 February 2016

First Responder & Keyboard Handling

First Responder & Keyboard Handling



Hi!

In IOS the First Responder has play a small role. But it is very important to handle the applications where keyboard is shown.

// Import basic UIKit Package
import UIKit

// Implement UITextFieldDelegate
class Sample_VC: UIViewController, UITextFieldDelegate 
{

// create UITextfield
@IBOutlet weak var et_un: UITextField!
    
@IBOutlet weak var et_pass: UITextField!

override func viewDidLoad() {
        super.viewDidLoad()

// Should fix delegate for self
et_un.delegate = self
et_pass.delegate = self

// Methods for Navigate UITextfield Up & Down on Main view while Typing 
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil);
        NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);


}

    func keyboardWillShow(sender: NSNotification) {
        self.view.frame.origin.y -= 150
    }
    
    func keyboardWillHide(sender: NSNotification) {
        self.view.frame.origin.y += 150
    }


// Implementation Method for UITextField Handl
func textFieldShouldReturn(textField: UITextField) -> Bool {
        if(textField == et_un)
        {
// Move to next UITextField
            et_pass.becomeFirstResponder()
        }
        else if(textField == et_pass)
        {
// Resign the FirstResponder
            et_pass.resignFirstResponder()
        }
        return false
    }


}

Thank You..,