Comments (138)

  1. I am very new to ios/swift from android background and is given a very short deadline keeping my job on stake.
    I am Struck at
    let res = response as NSHTTPURLResponse;
    where it gives error
    NSURLResponse? is not convertible to NSHTTPURLResponse;
    did you mean to use ‘as!’ force downcast.

    when i downcast response, it asks me to do it again at 4 different places again until my code settles. But then , when i run my code it to fetch String from a key value pair , it gives me some ridiculous random Integer. Please help me brother. I know my question may be stupid. Sorry to bother bro, but this job is my family’s bread n butter 🙁

  2. Frank

    Hi Dipin,

    Are you gonna update this tutorial to Xcode 6.3.1?

  3. John Beany

    Thanks for the tutorial!
    When I open this file (I have not made any modifications to the file) it says that there are 7 errors. I am using Xcode 6.3.2 (not a beta version).

    The errors are:

    Objective-C method ‘application:didFinishLaunchingWithOptions:’ provided by method ‘application(_:didFinishLaunchingWithOptions:)’ conflicts with optional requirement method ‘application(_:didFinishLaunchingWithOptions:)’ in protocol ‘UIApplicationDelegate’

    ‘NSString’ is not implicitly convertible to ‘String’; did you mean to use ‘as’ to explicitly convert?

    ‘AnyObject?’ is not convertible to ‘NSString’; did you mean to use ‘as!’ to force downcast?

    ‘NSString’ is not implicitly convertible to ‘String’; did you mean to use ‘as’ to explicitly convert?

    ‘NSURLResponse?’ is not convertible to ‘NSHTTPURLResponse!’; did you mean to use ‘as!’ to force downcast?

    ‘NSString’ is not implicitly convertible to ‘String’; did you mean to use ‘as’ to explicitly convert?

    ‘NSURLResponse?’ is not convertible to ‘NSHTTPURLResponse!’; did you mean to use ‘as!’ to force downcast?

    Any ideas how to fix these errors?

  4. John

    When I open it in Xcode 6.3.2 it gives me 5 errors! I haven’t changed anything in the file. I am also not using a beta version of Xcode. I am getting errors like:

    ‘NSString’ is not implicitly convertible to ‘String’; did you mean to use ‘as’ to explicitly convert?

    ‘NSURLResponse?’ is not convertible to ‘NSHTTPURLResponse!’; did you mean to use ‘as!’ to force downcast?

    ‘AnyObject?’ is not convertible to ‘String’; did you mean to use ‘as!’ to force downcast?

    ‘NSString’ is not implicitly convertible to ‘String’; did you mean to use ‘as’ to explicitly convert?

    ‘NSURLResponse?’ is not convertible to ‘NSHTTPURLResponse!’; did you mean to use ‘as!’ to force downcast?

    Any ideas how to fix these errors?

  5. shivam

    thanks for the tutorials
    hey can you continue your series by adding more tutorials like user profile or something like that

  6. shivam

    thanks sir, it worked perfectly
    can you continue your series by adding more tutorials like user profile or something like that
    thanks

  7. Hitesh

    Hi Dipin,

    I have tried to update the if statement to if(isset[$_POST]) but to no avail. Where exactly am I missing the &

    header(‘Content-type: application/json’);
    if($_POST) {
    $username = $_POST[‘username’];
    $password = $_POST[‘password’];
    $c_password = $_POST[‘confirmPassword’];

    if($_POST[‘username’]) { //if ($username && $password == $c_password) also doesnt work
    if ( $password == $c_password ) {

    $db_name = ‘laundryMembers’;
    $db_user = ‘root’;
    $db_password = ‘root’;
    $server_url = ‘localhost’;

  8. Hitesh

    Here is the php log. Is it something to do with the undefined index?

    [19-Apr-2015 01:51:02 Europe/Berlin] Success: 1
    [19-Apr-2015 01:51:02 Europe/Berlin] User ‘1password=1confirmPassword=1’ created.
    [19-Apr-2015 01:51:39 Europe/Berlin] User 1: password doesn’t match.
    [19-Apr-2015 01:51:48 Europe/Berlin] PHP Notice: Undefined index: password in /Applications/MAMP/htdocs/jsonsignup.php on line 10
    [19-Apr-2015 01:51:48 Europe/Berlin] PHP Notice: Undefined index: confirmPassword in /Applications/MAMP/htdocs/jsonsignup.php on line 11
    [19-Apr-2015 01:51:48 Europe/Berlin] Success: 1
    [19-Apr-2015 01:51:48 Europe/Berlin] User ‘2password=2confirmPassword=2’ created.
    [19-Apr-2015 02:20:14 Europe/Berlin] User 1: password doesn’t match.
    [19-Apr-2015 02:20:48 Europe/Berlin] User 1: password doesn’t match.
    [19-Apr-2015 02:20:56 Europe/Berlin] PHP Notice: Undefined index: password in /Applications/MAMP/htdocs/jsonsignup.php on line 10
    [19-Apr-2015 02:20:56 Europe/Berlin] PHP Notice: Undefined index: confirmPassword in /Applications/MAMP/htdocs/jsonsignup.php on line 11
    [19-Apr-2015 02:20:56 Europe/Berlin] Success: 1
    [19-Apr-2015 02:20:56 Europe/Berlin] User ‘112password=112confirmPassword=112’ created.
    [19-Apr-2015 02:21:26 Europe/Berlin] User 112: password doesn’t match.

  9. Hitesh

    Hi,

    Great tutorial! I am having an issue. After I sign up, I am not able to login with the same username/password. The username and password are created in the database successfully. Is it something to do with collation at phpmyAdmin? Can you please help.

    2015-04-18 20:35:59.722 LaundryTimer[4967:109617] Sucess: 1
    2015-04-18 20:35:59.722 LaundryTimer[4967:109617] Sign Up Success
    2015-04-18 20:36:02.611 LaundryTimer[4967:109617] PostData: username=12&password=12
    2015-04-18 20:36:02.615 LaundryTimer[4967:109617] Response code: 200
    2015-04-18 20:36:02.615 LaundryTimer[4967:109617] Response ==> {“success”:0,”error_message”:”Invalid Username/Password”}
    2015-04-18 20:36:02.616 LaundryTimer[4967:109617] Success: 0

  10. Andrew

    When trying to log in, I get an error saying A server with the specified hostname could not be found. I have changed the URL in the Swift code and changed the PHP file as much as I thought needed (DB name, username and password). Can you help at all?

  11. Hey,

    Can you make sure mysql is running?

    mysqladmin -u root -p status

    If its running, can you verify in my.cnf that socket file is set to ‘/var/lib/mysql/mysql.sock’.

    socket=/var/lib/mysql/mysql.sock

    Please check the permissions also:

    sudo chmod -R 777 /var/lib/mysql/

    Thanks.

  12. Neil

    So i have made my own mysql database and uploaded the two php to my website and changed all the login credentials to fit my database and set the url to the one that directs to my site (php) in loginvc and signupvc but as soon as i run the emulator for the app and hit register for signup i get cant connect to local MySql server through socket ‘/var/lib/mysql/mysql.sock’ (2).

  13. Vincenzo

    hello!
    First I want to thank you for this tutorial.
    I would like to ask you why when vao to login or sign up to me this error:
    “Access denied for user ‘json_login1 @ localhost’ (using password: YES).
    Thanks for the possible response

  14. You can use NSUserDefaults to store the info, during login.
    I already save the username in userdefaults.

    prefs.setObject(username, forKey: "USERNAME")

    Then later when they return, fill the login screen with the info from userdefaults.

  15. Gopinath

    Hi dipin sir,
    I am new to xcode. I want to create login screen with Remember me check box where it stores Username and password .Please guide me ThaksIn advance !!!

  16. Deep

    Hi

    Your tutorial was really helpful for me as it shows how to create outlet just by ctrl dragging from the UI controls. But i was trying to create one simple app which has gesture init.I dragged swipe gesture on my view and tried to create outlet as u shown in video by ctrl dragging from it on the view controller file in assistant editor.
    But i could not .
    I saw other tutorials too where they have used one more UIView for the sake of gesture. But again they were writing IBOutlet manually in editor. So i was thinking if one can really create IBOutlet and IBAction by ctrl dragging from swipe gesture onto the editor file?

  17. Hey,

    Its easy, you will have to pass the first name in the json reply during authentication.
    Parse it on the app side, store it in userdefaults/coredata.
    When you are on the Home screen retrieve it from where you have saved it and display it.

    Thanks.

  18. Diego

    Great tutorial!! Thanks a lot for this. I´m new in swift… and i was wondering, how it would be your approach in the case i want to show other data in the home label , for example, i connected your code to an existent mysql database, and it has a “firstname” table… well, instead of showing the Username like in your tutorial, i want to show the “firstname” of the database. Thanks.

  19. Waihibeachian

    Awesome tutorial! This was my first tutorial using swift and XCode and found it very useful especially the navigation of the XCode UI, wiring up the events, properties, and story board. Thanks!

  20. Mark

    Fixed the problem. md5 in this line was the problem: $stmt->bind_param(“ss”, $username, md5($password));

    So i did this instead:

    $userpass=md5($password);
    $stmt->bind_param(“ss”, $username, $userpass);

    and worked. Not sure why if in you online jsonlogin2.php works…

    Thanks.

  21. Mark

    This is the line 29.. $stmt->bind_param(“ss”, $username, md5($password));

    Its the same than on your file… i didn´t touch anything there…. Thats why i donñt get why it doesn´t work in my server.. Thanks.

  22. This is the response from your server:

    <br />
    <b>Strict Standards</b>:  Only variables should be passed by reference in <b>/home/digidevs/public_html/projects/fbpcompanion/jsonlogin2.php</b> on line <b>29</b><br />
    {"success":1}
  23. Mark

    Thanks for your quick reply. Yes, i tried again, and i received the same error…
    I signed up using my server and it worked perfect, the problem is with login… are you sure the file jsonlogin2.php i downloaded yesterday is the same than in https://dipinkrishna.com/jsonlogin2.php ? because as i said, when i used your url works, but when i change it to my server at var url:NSURL = NSURL(string: “http://digidevs.com/projects/fbpcompanion/jsonlogin2.php”)! i got the error…

    Could be something related to my server configuration? Thanks a lot!

  24. Thats, probably you are not getting data or the data returned is an invalid json string.

    Can you double check what you are receiving?

  25. Mark

    Everything works geat when i use your php files, in your server, but when i used on mine, i got : fatal error: unexpectedly found nil while unwrapping an Optional value and this part highlighted in green…

    let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as NSDictionary

    what can it be? Thanks.

  26. benga

    do I have to make a database with mysql and have a php file for this to work?

  27. benga

    hi, I tried this and copied everything etc from the downloadable source code but for some reason when i lunch the app, it stays on the home page even though there is not a login session. how can i fix this? there are no errors whats so ever.

  28. Miguel B

    do i have to remove your code entirely?

    or do i simply just change something like your URL?

  29. Miguel B

    Ok, So i got it working. I forgot to remove the old button references i made when watching your tutorial when i pasted over them with your codes above. I have everything working fine now. This tutorial is amazing!

    My question now is. When i develop my application, i would like to manage the users account. Is it possible to implement Parse to hold the data?

  30. Miguel B

    Hey, So i the codes working pefectly besides he create account part. In the simulator it gives me an error when i try to create an account. I would assume is because its using your PHP. How do i create my own and get it working?

  31. Theodore

    Dipin

    Thanks a lot for this tutorial, I am just starting out (not in life, just in coding) and it is great.

    Thanks again!

  32. Luc

    Hello,
    Thanks for your feedbacK;
    ok, so basically the main view controller is the HomeVC and then you check if the user is already signed in to go to the LoginVC if he is not ?
    Luc

Leave a comment

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.