so i start to make an app and i try so I started an application that allows to make a connection to a database. and i have also 2 signal SIGABRT error i put where the error spawn in my code. I met some errors and unfortunately I don't know how to fix it here is the log:
2022-11-08 18:27:45.563127+0100 test[19072:332743] [SceneConfiguration] Info.plist configuration "Default Configuration" for UIWindowSceneSessionRoleApplication contained UISceneClassName key, but could not load class with name "".
2022-11-08 18:27:45.563460+0100 test[19072:332743] [SceneConfiguration] Info.plist configuration "(no name)" for UIWindowSceneSessionRoleApplication contained UISceneClassName key, but could not load class with name "".
2022-11-08 18:27:45.564063+0100 test[19072:332743] [SceneConfiguration] Info.plist configuration "Default Configuration" for UIWindowSceneSessionRoleApplication contained UISceneClassName key, but could not load class with name "".
Could not cast value of type 'NSNull' (0x1b7cc9a28) to 'NSString' (0x1b7cc7ec8).
2022-11-08 18:27:45.631625+0100 test[19072:332954] Could not cast value of type 'NSNull' (0x1b7cc9a28) to 'NSString' (0x1b7cc7ec8).
Could not cast value of type 'NSNull' (0x1b7cc9a28) to 'NSString' (0x1b7cc7ec8).
CoreSimulator 857.13 - Device: iPhone 14 Pro (6E6732CE-5770-4803-96B8-07D2C8BBAF0E) - Runtime: iOS 16.1 (20B72) - DeviceType: iPhone 14 Pro
here is my homeModel :
import Foundation
import UIKit
protocol HomeModelDelegate {
func itemsDowloaded(client:[Client] )
}
class HomeModel : NSObject {
var delegate:HomeModelDelegate?
func getItems(){
//Hit the conn url
let serviceURL = "http://localhost/service.php"
//Download the JSON Data
let url = URL(string: serviceURL)
if let url = url {
// Create a URL Session
let session = URLSession(configuration: .default)
let task = session.dataTask(with: url) { (data, url, error) in
if error == nil {
//Succed
//call the parseJson
//signal SIGABRT
self.parseJson(data!)
}else{
//error
}
}
// Start the task
task.resume()
}
//notify the view controller and pass the data back
}
func parseJson(_ data:Data){
var clientArray = [Client] //() can't put () because error on the post
do {
//Parse the data into Client object
let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as! [Any]
//loop through each result in the json array
for jsonResult in jsonArray {
//Cast json result as a dictionary
//signal SIGABRT
let jsonDict = jsonResult as! [String:String]
//Create a new client and set properties
let cli = Client(id:jsonDict["id"]!,
lastName: jsonDict["nom"]!,
firstName: jsonDict["prenom"]!,
email: jsonDict["email"]!,
mdp: jsonDict["mdp"]!)
clientArray.append(cli)
}
// Pass the client array back to delegation
delegate?.itemsDowloaded(client: clientArray)
}
catch{
print("error parseJson")
}
}
}
Good morning,
so i managed to solve the problem by removing some properties in my client class because the data i was receiving was null, that's probably why i had this error.
for those who have the same problem check well in the php that you did not receive null data or in your database.
I will close the topic.