Tuesday 18 December 2018

Navigation Without Segue




let next = self.storyboard?.instantiateViewControllerWithIdentifier("homes_vc") as? UINavigationController
                    self.presentViewController(next!, animated: true, completion: nil)

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..,

Tuesday 27 October 2015

Custom UIButton In SWIFT

Hi!

The IOS developers are begin to move from the existing Objective-C into Brand New Sift.
In our existing Objective-C we have lot of library to make a customization .  Likewise in SWIFT also we can customize the UI. But if googled we can find very few amount of results only.

Now i have create a custom UIButton with Customize Border, Color, Background, Adjust the Button size depends on button Title & Padding around the title of Button.

Swift Class for Custom UIButton

import UIKit
import Foundation

class Btn: UIButton {

// init method for UIButton
    required init(coder aDecoder: NSCoder) {
// Override the Super class of UIButton
        super.init(coder:aDecoder)
// Make padding around the button 
        self.contentEdgeInsets = UIEdgeInsets(top: 2.0, left: 5.0, bottom: 2.0, right: 5.0)
// To adjust the button size depends on the button Title
        self.titleLabel?.adjustsFontSizeToFitWidth = true
// Minimum Label size 
        self.titleLabel!.minimumScaleFactor = 0.5
// Set the Radius size as 5.0

        self.layer.cornerRadius = 5.0;
// Set the Border Color & With
        self.layer.borderColor = UIColor.whiteColor().CGColor
        self.layer.borderWidth = 1.5
// Set the Background Color
        self.backgroundColor = UIColor.redColor()
// Set the Tint Color
        self.tintColor = UIColor.orangeColor()
    }



On your UIButton set the class as the Custom UIButton Class That's all..,

Enjoy!..,





Thank You!

Have A Happy Day..,


Thursday 25 June 2015

JSON Parsing in IOS using SWIFT

JSON Parsing in IOS using SWIFT


Hi!


About JSON!

JSON is a Very light weight framework to transfer data when compare with XML.

JSON in IOS!

Like Android, IOS also can transfer the data very fast and securely in JSOn format.

Today i am going to give an example about how to transfer the JSON data to IOS by using the Brand new SWIFT language.

Step 1:

     Create a new ios project using your XCODE. delete the default story board and its ViewController.

Step 2:

   On your StoryBoard  Place a Table View Controller, on your CELL change the Identifier name as "cell"

Step 3:

    Create a COcoa Touch new class with SubClass of UITableViewController after create the class configure as Custom Class of your StoreBoard Table View Controller.

Sample JSON Data :


{
    "Data": [
        {
            "AccountId": "xxxxxxxxxxxxxxxx",
            "AccountName": "xxxxxxxxxxxxxxxx",
            "Topic": "xxxxxxxxxxxxxxxx",
            "Discipline": "xxxxxxxxxxxxxxxx",
            "Source": "xxxxxxxxxxxxxxxx",
            "Email": "xxxxxxxxxxxxxxxx",
            "PhoneNumber": "xxxxxxxxxxxxxxxx",
            "URL": "xxxxxxxxxxxxxxxx"
        },
        {
            "AccountId": "xxxxxxxxxxxxxxxx",
            "AccountName": "xxxxxxxxxxxxxxxx",
            "Topic": "xxxxxxxxxxxxxxxx",
            "Discipline": "xxxxxxxxxxxxxxxx",
            "Source": "xxxxxxxxxxxxxxxx",
            "Email": "xxxxxxxxxxxxxxxx",
            "PhoneNumber": "xxxxxxxxxxxxxxxx",
            "URL": "xxxxxxxxxxxxxxxx"
        }
]
}

Step 4:


Create an Array to store your value


var TableData:Array<String>=Array<String>()



    On ViewDidLoad() method call your service


url_json_data("http://xxxxxx/xxxx/xxxx/xxxx/xxxxxx/xx")

On numberOfSectionsInTableView() Method Return "1" 

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1
    }



On tableView() Method

return your array value

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return TableData.count
    } 

On tableView() for cell function do the fallowing

the "cell" is the name what you have assigned in the step 2
   override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell

        cell.textLabel?.text=TableData[indexPath.row]
        return cell
    }

Method To Parsing the JSON

    func url_json_data(url:String)
        
    {
        
        let httpMethod = "GET"
        
        let timeout = 15
        
        let url = NSURL(string: url)
        
        let urlRequest = NSMutableURLRequest(URL: url!,cachePolicy: .ReloadIgnoringLocalAndRemoteCacheData,timeoutInterval: 15.0)
        
        let queue = NSOperationQueue()
        
        NSURLConnection.sendAsynchronousRequest(
            
            urlRequest,
            
            queue: queue,
            
            completionHandler: {(response: NSURLResponse!,
                
                data: NSData!,
                
                error: NSError!) in
                
                if data.length > 0 && error == nil{
                    
                    let json = NSString(data: data, encoding: NSASCIIStringEncoding)
                    
                    self.json_data_extractor(json!)
                    
                }else if data.length == 0 && error == nil{
                    
                    println("Nothing was downloaded")
                    
                } else if error != nil{
                    
                    println("Error happened = \(error)")
                    
                }
                
            }
            
        )
        
    }

Method to extract the JSON Data

    func json_data_extractor(data:NSString)
        
    {
        
        var parseError: NSError?
        
        let jsonData:NSData = data.dataUsingEncoding(NSASCIIStringEncoding)!
        
        let json: AnyObject? = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &parseError)
        
        if (parseError == nil)
            
        {
            
            if let countries_list = json as? NSDictionary
                
            {
                if let Data_obj_list = countries_list["Data"] as? NSArray
                {
                    println(Data_obj_list.count)
                    for(var i=0; i < Data_obj_list.count; i++)
                    {
                        if let country_obj = Data_obj_list[i] as? NSDictionary
                        {
                            if let country_name = country_obj["AccountName"] as? String
                                
                            {
                                
                                if let country_code = country_obj["Discipline"] as? String
                                    
                                {
                                    if let email_id=country_obj["Email"] as? String
                                    {
                                         TableData.append(country_name + " , " + country_code + " , " + email_id)
                                    }
                                    
                                }
                                
                            }
                        }
                        
                    }
                }
                
            }
            
        }
        
        refresh_table();
        
    }

Method to refresh the Table

   func refresh_table()
        
    {
        
        dispatch_async(dispatch_get_main_queue(), {
            
            self.tableView.reloadData()
            
            return
            
        })
        
    }


Thats All!

Enjoy The Code!

Have A Happy Day..,