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
import Foundation | |
import UIKit | |
struct CreditCard { | |
let number: String | |
let expirationDate: Date | |
} | |
class CreditCardView { | |
@IBOutlet private weak var numberTextView: UITextView! |
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
- (void)updateLeads { | |
NSFetchRequest *leadsFetchRequest = [NSFetchRequest fetchRequestWithEntityName:[PCLead entityName]]; | |
leadsFetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"surname" ascending:YES]]; | |
self.leads = [self.managedObjectContext executeFetchRequest:leadsFetchRequest error:NULL]; | |
[self.tableView reloadData]; | |
} |
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
// In PCLeadsViewController | |
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
if ([segue.identifier isEqualToString:@"DisplayLeadSegue"]) { | |
PCLeadViewController *leadViewController = segue.destinationViewController; | |
NSIndexPath *selectedRowIndexPath = [self.tableView indexPathForSelectedRow]; | |
leadViewController.lead = self.leads[selectedRowIndexPath.row]; | |
} else { | |
PCNewLeadViewController *newLeadViewController = segue.destinationViewController; | |
newLeadViewController.managedObjectContext = self.managedObjectContext; |
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
// Header file | |
@protocol PCNewLeadViewControllerDelegate <NSObject> | |
- (void)newLeadWasCreated; | |
@end | |
@interface PCNewLeadViewController : UIViewController |
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
@implementation PCLead | |
@dynamic name; | |
@dynamic surname; | |
@dynamic company; | |
+ (instancetype)insertLeadInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext { | |
return [NSEntityDescription insertNewObjectForEntityForName:self.entityName inManagedObjectContext:managedObjectContext]; | |
} |
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
@interface PCAppDelegate () | |
@property PCPersistentStack *persistentStack; | |
@end | |
@implementation PCAppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
self.persistentStack = [[PCPersistentStack alloc] initWithStoreURL:[self storeURL] modelURL:[self modelURL]]; |
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
// Header file | |
@interface PCPersistentStack : NSObject | |
@property (readonly) NSManagedObjectContext *managedObjectContext; | |
- (instancetype)initWithStoreURL:(NSURL*)storeURL modelURL:(NSURL*)modelURL; | |
- (void)saveContext; | |
@end |
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
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
PCLeadViewController *leadViewController = segue.destinationViewController; | |
NSIndexPath *selectedRowIndexPath = [self.tableView indexPathForSelectedRow]; | |
leadViewController.lead = self.leads[selectedRowIndexPath.row]; | |
} |
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
@interface PCLeadsViewController () | |
@property NSArray *leads; | |
@end | |
@implementation PCLeadsViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; |
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
@interface PCLeadCell () | |
@property (weak, nonatomic) IBOutlet UILabel *nameLabel; | |
@property (weak, nonatomic) IBOutlet UILabel *companyLabel; | |
@end | |
@implementation PCLeadCell | |
- (void)setLead:(PCLead *)lead { |
NewerOlder