This file contains hidden or 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
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 |
This file contains hidden or 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
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() | |
}) |
This file contains hidden or 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
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) |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
Alamofire.request(Method, URLStringConvertible, parameters: [String : AnyObject]?, encoding: ParameterEncoding, headers: [String : String]?).response { | |
} |
This file contains hidden or 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
import Foundation | |
import SwiftyJSON | |
class User { | |
var name : String! | |
var username : String! | |
var password : String! | |
var id : String! | |
static var loggedInUser = User() | |
This file contains hidden or 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
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 |
This file contains hidden or 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
protocol BaseRequestProtocol { | |
var baseRequest : BaseRequest { get set } | |
} |
This file contains hidden or 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
extension BaseRequestProtocol { | |
var baseURL : NSURL { | |
get { | |
return self.baseRequest.baseURL | |
} | |
set { | |
self.baseRequest.baseURL = newValue | |
} | |
} |