Skip to content

Instantly share code, notes, and snippets.

do {
try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: "SQLStorage", URL: url, options: nil)
} catch {
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error as NSError
let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
appDelegate?.managedObjectContext.performBlock({
let account = NSEntityDescription.insertNewObjectForEntityForName("AccountInfo", inManagedObjectContext: (appDelegate?.managedObjectContext)!) as! AccountInfo
account.accountnumber = "12345ABCD"
account.amount = NSNumber(integer: Int(1000))
account.belongsTo = self.foundPerson!
try! appDelegate?.managedObjectContext.save()
})
import Foundation
import Alamofire
import SwiftyJSON
class LoginController {
func loginUserWith(userName username : String, andPassword password : String, withCompletionBlock completionBlock : (Bool) -> ()) {
Alamofire.request(.GET, (NSURL(string:"http://idontknowurl.com/getUser"))!, parameters: ["username" : username,"password" : password], encoding: .URL, headers: [:]).responseJSON {
response in
print(response)
import Foundation
import Alamofire
class UserProfileController {
func fetchUserProfileInfo(forCurrentUser user : User, withCompletionBlock completionBlock : (NSError?) -> ()) {
Alamofire.request(.POST, (NSURL(string: "http://idontknowurl.com/getUserProfile"))!, parameters: ["userId" : user.id], encoding: .URL, headers: ["username" : user.username, "password" : user.password]).response {
response in
//process response here
//configure user
//if no error
import Foundation
import Alamofire
class FriendsListController {
func fetchFriendsList(forUser user : User, completionBlock block : (NSError?) -> ()) {
Alamofire.request(.POST, (NSURL(string: "http://idontknowurl.com/getFriendsList"))!, parameters: ["userId" : user.id,"friendsLevel" : "Gmail"], encoding: .URL, headers: ["username" : user.username, "password" : user.password]).response {
response in
//process response here
//configure user
//if no error
Alamofire.request(Method, URLStringConvertible, parameters: [String : AnyObject]?, encoding: ParameterEncoding, headers: [String : String]?).response {
}
import Foundation
import SwiftyJSON
class User {
var name : String!
var username : String!
var password : String!
var id : String!
static var loggedInUser = User()
import Foundation
import Alamofire
//This is a base request struct
struct BaseRequest {
var baseURL : NSURL
var endpoint: String?
var method: Alamofire.Method
var parameterEncoding : ParameterEncoding
protocol BaseRequestProtocol {
var baseRequest : BaseRequest { get set }
}
extension BaseRequestProtocol {
var baseURL : NSURL {
get {
return self.baseRequest.baseURL
}
set {
self.baseRequest.baseURL = newValue
}
}