# User Login with Swift

**URL:** <https://community.dreamfactory.com/t/user-login-with-swift/1695>\
**Category:** Code Examples\
**Created:** [October 31, 2015, 5:17pm UTC](https://community.dreamfactory.com/t/user-login-with-swift/1695 "2015-10-31T17:17:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gavin\_Beard](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/gavin_beard/32/976_2.png) [@Gavin\_Beard](https://community.dreamfactory.com/u/Gavin_Beard)\
**Post date:** [October 31, 2015, 5:17pm UTC](https://community.dreamfactory.com/t/user-login-with-swift/1695/1 "2015-10-31T17:17:33Z")

</div>

Hi all,

Apologies if I have missed this, but I’ve done a quick search and couldn’t find a solid example. Has anyone managed to write anything to log into Dreamfactory (or even better, user registration) that uses Swift. I’ve tried with a combination of NSURL and AlamoFire but been unsuccessful as I get an error {“error”:{“context”:null,“message”:“Unrecognized payload type”,“code”:400}

Code:

```
    let uri = NSURL(string: "\(baseUserUrl)session")!
    
    let mutableURLRequest = NSMutableURLRequest(URL: uri)

    let manager = Alamofire.Manager.sharedInstance
    manager.session.configuration.HTTPAdditionalHeaders = ["X-DreamFactory-Api-Key":"xxx"]
    manager.request(.POST,mutableURLRequest,parameters:["email":"xxx@xxx.xxx","password":"xxx","duration":0]).response { request, response, data, error in
        print(request)
        print(response)
        print(NSString(data: data!, encoding: NSUTF8StringEncoding))
    }

```

Kind Regards

Gavin

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [November 3, 2015, 7:11pm UTC](https://community.dreamfactory.com/t/user-login-with-swift/1695/2 "2015-11-03T19:11:02Z")

</div>

Here is the login example from [the iOS example app](https://github.com/dreamfactorysoftware/ios-sdk), but I think it’s written in objective C rather than the new Swift:

```auto
NSString *serviceName = @"user";
NSString *resourcePath = @"session";
NSString *restApiPath = [NSString stringWithFormat:@"%@/%@/%@", baseUrl, serviceName, resourcePath];
NSDictionary* requestBody = @{@"email":self.emailTextField.text,
                              @"password":self.passwordTextField.text};

```

Since I assume that doesn’t help, I have moved this topic to the [Code Examples](https://community.dreamfactory.com/c/code-examples) category so that hopefully someone in the community who’s using Swift can chime in with a snippet of their app.
