Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import Alamofire
- import SwiftyJSON
- class Login {
- var userName:String!
- var passWord:String!
- init(userName : String, passWord : String) {
- let parameters = [
- "username": userName,
- "password": passWord
- ]
- Alamofire.request(.POST, "http://anyapi.com", parameters: parameters)
- .responseJSON { response in
- print(response.request)
- print(response.response)
- print(response.data)
- print(response.result)
- if let result = response.result.value {
- print("Did receive JSON data: (result)")
- let value = JSON(result)
- if let api_key = value["api_token"].string {
- print("The token is " + api_key)
- } else{
- print("error parsing api token")
- }
- //pass data to Users class
- _ = Users.init(Name: value["name"].string, Email: value["email"].string, Id: value["id"].string, ProfilePicture: value["profile_picture"].string, Username: value["username"].string)
- }
- else {
- print("JSON data is nil.")
- }
- }
- }
- }
- import Foundation
- import Alamofire
- import SwiftyJSON
- class Users {
- private var _name: String!
- private var _email: String!
- private var _userId: String!
- private var _profilePicture: String!
- private var _username: String!
- var particulars: [String] = []
- var name: String {
- _name = particulars[0]
- return _name
- }
- var email: String {
- _email = particulars[1]
- return _email
- }
- var userId: String {
- _userId = particulars[2]
- return _userId
- }
- var profilePicture: String {
- _profilePicture = particulars[3]
- return _profilePicture
- }
- var username: String {
- _username = particulars[4]
- return _username
- }
- required init?(Name: String?, Email: String?, Id: String?, ProfilePicture: String?, Username: String?) {
- particulars += ["(Name)"]
- particulars += ["(Email)"]
- particulars += ["(Id)"]
- particulars += ["(ProfilePicture)"]
- particulars += ["(Username)"]
- }
- }
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var usernameLabel: UILabel!
- // var usernameLabelText = String()
- var usernameLabelText: String? {
- return String(Users.username)
- }
- override func viewDidLoad() {
- usernameLabel.text = "Welcome (usernameLabelText)"
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement