Sunday 20 May 2018

Reading data from Local Json file using Alamofire in swift3


//Reading data from Local Json file instead of Service urls using Alamofire in swift3


func getwordmeaningdata()
  {
   
    if let path = Bundle.main.path(forResource: "localfile", ofType: "json") {
       let url=URL(fileURLWithPath: path)
        Alamofire.request(url).responseJSON { response in
            
            if let JSON = response.result.value {
                print("JSON: \(JSON)") 
            }
        }
}


//This is the data of local json file not getting from URL
localfile.json


{
  "person":[
    {
      "name": "Bob"
     
    },
    {
      "name": "Vinny"
      }

]
}

Tuesday 15 May 2018

Read data from textfile in swift 3


let path = Bundle.main.path(forResource: "textfile", ofType: "txt")
 print(path!)
                
let url = URL(fileURLWithPath: path!)
 print(url)
                
 let contentString:String = try! String(contentsOf: url, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))

//if convert to Data

 let data = contentString.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue), allowLossyConversion: false)!
                        

print("string\(contentString)")


Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...