Created
July 22, 2015 19:36
-
-
Save derrick-branch/61d4707374399a077c40 to your computer and use it in GitHub Desktop.
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
// 1. Get list of previous contacts from NSUserDefaults | |
NSMutableArray *previousContacts = | |
[[[NSUserDefaults standardUserDefaults] objectForKey:@"contacts"] mutableCopy]; | |
if (!previousContacts) previousContacts = [NSMutableArray array]; | |
// 2. Add new contact to list | |
self.url = [[Branch getInstance] getShortURLWithParams:@{@"email": self.emailTextField.text}]; // [see note 2] | |
NSDictionary *newContact = @{ @"name": self.nameTextField.text, | |
@"email": self.emailTextField.text, | |
@"company": self.companyTextField.text, | |
@"url": self.url, | |
@"from": self.currentUsername, | |
@"date": [NSDate date] }; | |
[previousContacts addObject:newContact]; | |
// 3. Save list in NSUserDefaults — TODO: save to robust data store | |
[[NSUserDefaults standardUserDefaults] setObject:previousContacts forKey:@"contacts"]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment