Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

POST API call in swift

 let url = URL(string: <#T##URL String#>)
        guard let requestUrl = url else { fatalError() }
        var request = URLRequest(url: requestUrl)
        request.httpMethod = "POST"
        // Set Request Header
        request.setValue("application/json", forHTTPHeaderField: "Accept")
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        
        // Set HTTP Body
        let newTodoItem = RequestModel(id: 300, task: "")
        let jsonData = try JSONEncoder().encode(newTodoItem)
        request.httpBody = jsonData
        // Make Request
            let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
                
                if let error = error {
                    print("Error took place (error)")
                    return
                }
                guard let data = data else {return}
                
         
        }
        task.resume()
Comment

PREVIOUS NEXT
Code Example
Swift :: swiftui pull to refresh 
Swift :: swift dispatch queue 
Swift :: swift reload tableview 
Swift :: button color swiftui 
Swift :: how to insert element at start of the array ios swift 
Swift :: swift enum 
Swift :: show back button in navbar swift 
Swift :: swift url request 
Swift :: difference between struct and class swift 
Swift :: swift push view controller programmatically 
Swift :: swiftui textfield height 
Swift :: change image tint color swiftui 
Swift :: change placeholder color swift 
Swift :: swift 5 make image fit uiimageview 
Swift :: simple alert swifti 
Swift :: how to merge 2 arrays in swift 
Swift :: add callbacks to view swiftui 
Swift :: Play Video in AVPlayer Sample Code Swift 
Swift :: swift replace newlines with space 
Swift :: swift function declaration 
Swift :: two value sum in swift 
Swift :: swift hide button 
Swift :: abs swift 
Swift :: swift loop through array of objet 
Swift :: SwiftUI cant tap in spacer of HStack 
Swift :: swiftui calendar 
Swift :: Swift Nested Tuple 
Swift :: selenium lfor loops 
Swift :: swift 1 to n array 
Swift :: Swift Function with Return Multiple Values 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =