So I want to get data from MySql I'm using PHP
<?php
// Create connection
$con=mysqli_connect("cantshowthis","hehe","sorry",":c");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// This SQL statement selects ALL from the table 'Registro'
$sql = "SELECT * FROM Registro";
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}
// Close connections
mysqli_close($con);
?>So i had multiples issues with Xcode that i don't understand quite well
1.- Ambiguous reference to member 'jsonObject(with:options:)'
This is the part of the code where the user MUST click the button to LOG IN
@IBActionfunc iniciarSesion(_ sender: UIButton) {
if Email.text == "" || Contrasena.text == ""{
displayAlert(title: "Información Faltante", message: "Debes porporcionar un correo y contraseña")
}
let myURL = NSURL(string: "https://cantshowthis.php")
let request = NSMutableURLRequest(url: myURL! as URL)
request.httpMethod = "POST"
let posString = "Correo=\(Email.text)&Password=\(Contrasena.text)"
request.httpBody = posString.data(using: String.Encoding.utf8)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
data, response, error in
if error != nil{
print("error=\(error)")
return
}
var err : NSError?
var json = JSONSerialization.jsonObject(with: data, options: .mutableContainers, error: &err) as? NSDictionary
if let parseJSON = json {
var resultValue:String = parseJSON["status"] as! String!;
print("message: \(resultValue) ")
if (resultValue == "success")
{
NSUserDefaults.StandarUserDefaults().setBool(true, value(forKey: "isUserLoggedIn"): )
NSUserDefaults.StandarUserDefaults().synchronize()
}
}
}
task.resume()
}this is the part where I'm getting the error because is red, I think this is an old version of coding I'm using Xcode 10
var err : NSError?
var json = JSONSerialization.jsonObject(with: data, options: .mutableContainers, error: &err) as? NSDictionary
if let parseJSON = json {
var resultValue:String = parseJSON["status"] as! String!;
print("message: \(resultValue) ")
if (resultValue == "success")
{
NSUserDefaults.StandarUserDefaults().setBool(true, value(forKey: "isUserLoggedIn"): )
NSUserDefaults.StandarUserDefaults().synchronize()
}
}
}
task.resume()