2

this is the view controller when I press the button this error appears

this the class that I create instance from it after creating that instance the error appears MC Reading from private effective user settings.

import UIKit

class authentication: NSObject {


    func runCode(password: String,email: String,name: String,  completionHandler:@escaping (Bool) ->()){

        struct f {
        static var flag = false

        }

        let Points : Int = 0

        let  passwardV : String = password

        let emailV : String = email

        let nameV : String = name

            // connect data base
            var request = URLRequest(url: URL(string: "https://www./////.com/API/register.php")!)
            // POST method
            request.httpMethod = "POST"
            // post senteace
            let postString = "Password="+passwardV+"&Email="+emailV+"&Name="+nameV

            request.httpBody = postString.data(using: .utf8)

            let task = URLSession.shared.dataTask(with: request) { data, response, error in
                guard let data = data, error == nil else {
                    // check for fundamental networking error
                    print("error=\(error)")
                    return
                }

                //parsing the response
                do {
                    //converting resonse to NSDictionary and get JSON result
                    let myJSON =  try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? NSDictionary
                    // receving json result
                    print(myJSON!)

                    if(myJSON!["error"] as! Bool == true){


                        print("alert")
                        f.flag =  false


           }
                    else {



                        print(myJSON!)
                        // save enformation in user's divice
                        let defaults = UserDefaults.standard

            defaults.set(nameV, forKey:"Name")

                       defaults.set(emailV, forKey:"Email")

                       defaults.set(Points, forKey:"Point")


                        defaults.synchronize()

                        //self.shouldPerformSegue(withIdentifier: "TOHomeCustomerVC", sender: self)
                    f.flag = true

                    }






                } catch let error as NSError {
                    print(error)

                }


            }

            completionHandler(f.flag)

            task.resume()
        }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Leena
  • 21
  • 3
  • Is it just a message or does the app fail in some way? If the app works it may be related to this answer: http://stackoverflow.com/a/40458288/1736679 – Efren May 16 '17 at 04:41
  • Also note the comment in the edit, please give more details in the question. – Efren May 16 '17 at 04:46

0 Answers0