User Login with Swift

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}


    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":"","password":"xxx","duration":0]).response { request, response, data, error in
        print(NSString(data: data!, encoding: NSUTF8StringEncoding))

Kind Regards


Here is the login example from the iOS example app, but I think it’s written in objective C rather than the new Swift:

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

Since I assume that doesn’t help, I have moved this topic to the Code Examples category so that hopefully someone in the community who’s using Swift can chime in with a snippet of their app.