Last active
March 3, 2016 00:33
-
-
Save MariuszWisniewski/eaf84a9b8ca1c313a5bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// iOS | |
// | |
// Created by Mariusz Wisniewski on 2/18/16. | |
// Copyright © 2016 Mariusz Wisniewski. All rights reserved. | |
// | |
import UIKit | |
import syncano_ios | |
import SDWebImage | |
class MyProfile : SCUserProfile { | |
var first_name : String? | |
var email : String? | |
var avatar : SCFile? | |
} | |
class ViewController: UIViewController { | |
@IBOutlet weak var imageView: UIImageView! | |
let syncano = Syncano.sharedInstanceWithApiKey("API_KEY", instanceName: "INSTANCE_NAME") | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.getUserProfile() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
func getUserProfile() { | |
SCUser.registerClassWithProfileClass(MyProfile.self) | |
SCUser.currentUser()?.logout() | |
SCUser.loginWithUsername("a", password: "a") { error in | |
let profile = SCUser.currentUser().profile as? MyProfile | |
// method 1 | |
profile?.avatar?.fetchInBackgroundWithCompletion({ data, error in | |
let image = UIImage(data: data) | |
self.imageView.image = image | |
print(profile?.avatar?.fileURL) | |
}) | |
// method 2 | |
if let url = profile?.avatar?.fileURL { | |
self.imageView.sd_setImageWithURL(url) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment