Skip to main content

Posts

Check for internet connection in iOS App Swift

Check Internet Connection if you are going in your application, Your Connection are Cellular & WIFI are ON/OFF.

First your create a Network swift class then implement where are you check connection on/off let start:- a  create public class Reachability 

import Foundation import UIKit import SystemConfiguration
publicclass Reachability { classfunc isConnectedToNetwork() -> Bool { var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0)) zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress)) zeroAddress.sin_family = sa_family_t(AF_INET) let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) { $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress) } } var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0) ifSCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) == false { r…
Recent posts

Nested JSON Parsing with Alamofire and SwiftyJSON in Swift 4

Build A Simple API (Custom JSON) with Alamofire & SwiftyJSON 


This Full Example helps to design a UIViewController WithOut StoryBoard with a UITableViewController, Custom Cell design to show data ion to api service json, this Tutorial  helps to understand how to use Alamofire with SwiftyJSON to hit an API and fetch results, parse them and show the results in an UITableViewController.
A Nested JSON :- like /*{ "id": "c200", "name": "Ravi Tamada", "email": "ravi@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } } */
Web Service api -  https://api.androidhive.info/contacts/ parse the data and show result in tableView.
First create pod file install Alamofire and SwiftyJSON API
Open Terminal -> Then go source folder …

How to Creating A Web Browser With in WKWebView

Create a simple Application open web URL in to WKWebView! or open web Browser WKWebView.

iOS Developer Live - There are Two Different Type open url with web view, UIWebView or WKWebView. Before iOS 8.0 Used UIWebView. Now After iOS 8.0 or Later apple introduce A New Claas WKWebView in the Library  WebKit. WKWebView faster to fast load webpage and more batter than UIWebView, its do not overload memory.
Example  Add code your ViewController class
import UIKit import WebKit
class ViewController: UIViewController, WKNavigationDelegate { var webView : WKWebView! overridefunc viewDidLoad() { super.viewDidLoad() // loading URL : let studyPlusUrl = "https://www.iosdeveloperlive.com/" let url = URL(string: studyPlusUrl) let request = URLRequest(url: url! asURL) // init and load request in webview. webView = WKWebView(frame: self.view.frame) webView.navigationDelegate = self webView.load(request) webView.allowsBackForwardNavigationGestures = true self.view.addSubview(webView) self.view.sendSubview(to…

Control Flow Statements - statements used in swift

List out what is the control transfer statements used in swift
Control flow statements are used to control the flow of execution in a program. There are several types of control flow statements in Swift, including loop statements, branch statements, and control transfer statements.  1.Loop statements allow a block of code to be executed repeatedly 2. Branch statements allow a certain block of code to be executed only when certain conditions are met 3.Control transfer statements provide a way to alter the order in which code is executed. 4.Swift provides a do statement to introduce scope, and catch and handle errors, 5.Defer statement for running cleanup actions just before the current scope exits.



Loop Statements -
Loop statements allow a block of code to be executed repeatedly, depending on the conditions specified in the loop. Swift there are three loop statements ·For-in statement ·While statement ·Repeat-while statement A for-in statement allows a block of code to be executed once for ea…

Enum & Enumeration in Swift 4

An Enum & Enumeration consists of integral constants

"An enumeration is a user-define data type which consists of a set of related value" Is used to define enum keyword" 

enum type { const1, const2, const3, .......}
enum week {
          case Monday
          case Tuesday
         .....
         case Sunday
}
Swift Example :- enum Country {
   case India
   case America
   case Russia
   case Chaina
}
var power = Country.America
power = .America
switch power {
   case .India:
      print("India Country is No 4")
   case .America:
      print("America Country is No 1")
   case . Russia:
      print("Russia Country is No 2")
   case . Chaina:
      print("Chaina Country is No 3")
}

Output is America Country is No 1

Rest Api in swift 4 Using URLSession And JSONSerialization Xcode 9 Example

A Short Example call Rest Api with JSON Foundation framework NSURLSession and NSJSONSerialization -



Getting Started - Basic Rest API request with Swift 4

func restApiRequest(){
let sessionConfig = URLSessionConfiguration.default
// Session Configuration
        let sessionUrl = URLSession(configuration: sessionConfig)
// Load configuration into Session
        let url = URL(string: "YOUR URL STRING")!
        let task = sessionUrl.dataTask(with: url, completionHandler: {
            (data, response, error) in
                if error != nil {
                    print(error!.localizedDescription)
                } else {
                    do {
                        if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]
                        {
                            print(json)
                        }
                    } catch {
                        print("error in JSONSerialization")
               …

iOS MapKit Tutorial: Getting Started Search Location and Directions on Mapkit

MapKit is a really useful API available on iOS devices that makes it easy to display maps, user locations with locality, and even draw routes your location to your destination.
Getting Started User Location
Create a new project single view appplication in Swift. - MKLocationMap


Open Info.plist from the Project navigator and configure the location permission prompt message NSLocationWhenInUseUsageDescription
Add "NSLocationAlwaysAndWhenInUseUsageDescription" instead of "Privacy - Location Always and When in use usage description".


ViewController.swift:
import UIKit import MapKit
protocol HandleMapSearch { func dropPinZoomIn(placemark:MKPlacemark) } class ViewController: UIViewController{ let locationManager = CLLocationManager() var resultSearchController:UISearchController! var selectedPin:MKPlacemark? @IBOutletvar mapView: MKMapView! overridefunc viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. locationManager.delegat…