-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNATRecipe.m
54 lines (41 loc) · 1.52 KB
/
NATRecipe.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// NATRecipe.m
// Breakfast Superfoods
//
// Created by Noah Teshu on 9/19/14.
// Copyright (c) 2014 Noah Teshu. All rights reserved.
//
#import "NATRecipe.h"
@implementation NATRecipe
- (instancetype)initWithIngredients:(NSArray *)ingredients recipeImage:(UIImage *)recipeImage label:(NSString *)label recipePreparation:(NSString *)recipePreparation
{
self = [super init];
_ingredients = ingredients;
_recipeImage = recipeImage;
_label = label;
_recipePreparation = recipePreparation;
return self;
}
//note: all properties added to recipe must be encoded here
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.ingredients forKey:@"ingredients"];
[aCoder encodeObject:UIImagePNGRepresentation(self.recipeImage) forKey:@"recipeImage"];
[aCoder encodeObject:self.label forKey:@"label"];
[aCoder encodeObject:self.recipePreparation forKey:@"recipePreparation"];
}
//note: all properties added to recipe must be decoded here
- (id)initWithCoder:(NSCoder *)aDecoder // NS_DESIGNATED_INITIALIZER
{
self = [super init];
_ingredients = [aDecoder decodeObjectForKey:@"ingredients"];
_recipeImage = [UIImage imageWithData:[aDecoder decodeObjectForKey:@"recipeImage"]];
_label = [aDecoder decodeObjectForKey:@"label"];
_recipePreparation = [aDecoder decodeObjectForKey:@"recipePreparation"];
return self;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"title: %@ \n ingredients: %@", self.label, self.ingredients];
}
@end