Skip to content

Instantly share code, notes, and snippets.

View matteom's full-sized avatar

Matteo Manferdini matteom

View GitHub Profile
@matteom
matteom / gist:7545009
Last active December 28, 2015 18:39
Initializing of labels in the Lead View Controller
@interface PCLeadViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *surnameLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@end
- (void)viewDidLoad {
[super viewDidLoad];
@matteom
matteom / gist:7545617
Created November 19, 2013 13:48
View Controller with Dynamic Type
@interface PCLeadViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *surnameLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *captionLabels;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *labels;
@end
@matteom
matteom / gist:7546424
Created November 19, 2013 14:48
Required UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 7;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"LeadCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
@matteom
matteom / gist:7546811
Created November 19, 2013 15:13
Model class for leads
@interface PCLead : NSObject
@property NSString *name;
@property NSString *surname;
@property NSString *company;
@end
@matteom
matteom / gist:7546897
Created November 19, 2013 15:18
Leads table view controller populating the table view from a plist file
@interface PCLeadsViewController ()
@property NSArray *leads;
@end
@implementation PCLeadsViewController
- (void)viewDidLoad {
[super viewDidLoad];
@matteom
matteom / gist:7546844
Last active December 28, 2015 18:59
Table view cell for leads
@interface PCLeadCell ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@end
@implementation PCLeadCell
- (void)setLead:(PCLead *)lead {
@matteom
matteom / gist:7547296
Created November 19, 2013 15:41
Passing data from the table view controller to the lead view controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
PCLeadViewController *leadViewController = segue.destinationViewController;
NSIndexPath *selectedRowIndexPath = [self.tableView indexPathForSelectedRow];
leadViewController.lead = self.leads[selectedRowIndexPath.row];
}
@matteom
matteom / gist:7548392
Last active December 28, 2015 19:09
Core data persistent stack
// Header file
@interface PCPersistentStack : NSObject
@property (readonly) NSManagedObjectContext *managedObjectContext;
- (instancetype)initWithStoreURL:(NSURL*)storeURL modelURL:(NSURL*)modelURL;
- (void)saveContext;
@end
@matteom
matteom / gist:7548487
Created November 19, 2013 16:49
Initializing the core data stack in the app delegate
@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]];
@matteom
matteom / gist:7548845
Created November 19, 2013 17:13
Creating new leads in Core Data
@implementation PCLead
@dynamic name;
@dynamic surname;
@dynamic company;
+ (instancetype)insertLeadInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext {
return [NSEntityDescription insertNewObjectForEntityForName:self.entityName inManagedObjectContext:managedObjectContext];
}