Skip to content

Commit d742903

Browse files
committed
Commented the property array to indicate why it is structured the way it is, fixed issue where the Address label would jump when switching from A-D to E.
1 parent 6c4e36b commit d742903

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

KVC Validation Pattern/KVC Validation Pattern/CTCViewController.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ - (void)viewDidLoad {
4040

4141
- (void)displayInfoForStation:(CTCStation*)station {
4242
_currentStation = station;
43-
44-
NSLog(@"%@", station);
45-
43+
4644
[self.tableView reloadData];
4745
}
4846

@@ -68,8 +66,6 @@ - (IBAction)viewJSONTapped:(id)sender {
6866
}
6967

7068
- (void)responseSegmentedControlDidChange:(id)sender {
71-
NSLog(@"Response changed to %@", [self.responseSegmentedControl titleForSegmentAtIndex:self.responseSegmentedControl.selectedSegmentIndex]);
72-
7369
NSString *json = [self jsonStringForResponse:self.responseSegmentedControl.selectedSegmentIndex];
7470

7571

@@ -155,14 +151,17 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
155151
cell.textLabel.text = NSLocalizedString(@"Name", nil);
156152
cell.detailTextLabel.text = _currentStation.stationName;
157153

154+
158155
} else if (indexPath.row == 1) {
159156
cell.textLabel.text = NSLocalizedString(@"Price", nil);
160157
cell.detailTextLabel.text = [self stringForPrice:_currentStation.price];
161158

159+
162160
} else if (indexPath.row == 2) {
163161
cell.textLabel.text = NSLocalizedString(@"Sells Diesel", nil);
164162
cell.detailTextLabel.text = _currentStation.sellsDiesel ? NSLocalizedString(@"Yes", nil) : NSLocalizedString(@"No", nil);
165163

164+
166165
} else if (indexPath.row == 3) {
167166
CTCAddress *address = _currentStation.address;
168167

@@ -171,7 +170,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
171170
if (address != nil) {
172171
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@\n %@, %@ %@", address.street, address.city, address.state, address.zip];
173172
} else {
174-
cell.detailTextLabel.text = @"";
173+
cell.detailTextLabel.text = @"\n "; // prevents Address label from jumping around between real and empty strings
175174
}
176175

177176
cell.detailTextLabel.numberOfLines = 2;

KVC Validation Pattern/KVC Validation Pattern/Model/CTCBaseModel.m

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@
1111
#import "NSString+Utilities.h"
1212
#import "ValidationFunctions.h"
1313

14-
#define kPropertyTypesArray @[@"Unknown",@"NSString", [NSString stringWithFormat:@"%s",@encode(BOOL)], @"NSNumber", @"i", @"f", @"NSArray", @"NSMutableArray", @"NSDictionary", @"NSMutableDictionary", @"I", @"NSDate", @"d"]
15-
1614
typedef NS_ENUM(NSUInteger, CTCPropertyType){
17-
CTCPropertyUnknown = 0, /**< Property type is unknown */
18-
CTCPropertyTypeString, /**< Property is an NSString */
19-
CTCPropertyTypeBool, /**< Property is a BOOL */
20-
CTCPropertyTypeNumber, /**< Property is an NSNumber */
21-
CTCPropertyTypeInteger, /**< Property is an NSInteger */
22-
CTCPropertyTypeFloat, /**< Property is a float */
23-
CTCPropertyTypeArray, /**< Property is an NSArray */
24-
CTCPropertyTypeMutableArray, /**< Property is an NSMutableArray */
25-
CTCPropertyTypeDictionary, /**< Property is an NSDictionary */
26-
CTCPropertyTypeMutableDictionary, /**< Property is an NSMutableDictionary */
27-
CTCPropertyTypeUnsignedInteger, /**< Property is an NSUInteger */
28-
CTCPropertyTypeDate, /**< Property is an NSDate */
29-
CTCPropertyTypeDouble /**< Property is a double */
15+
CTCPropertyUnknown = 0, // Property type is unknown
16+
CTCPropertyTypeString, // Property is an NSString
17+
CTCPropertyTypeBool, // Property is a BOOL
18+
CTCPropertyTypeNumber, // Property is an NSNumber
19+
CTCPropertyTypeInteger, // Property is an NSInteger
20+
CTCPropertyTypeFloat, // Property is a float
21+
CTCPropertyTypeArray, // Property is an NSArray
22+
CTCPropertyTypeMutableArray, // Property is an NSMutableArray
23+
CTCPropertyTypeDictionary, // Property is an NSDictionary
24+
CTCPropertyTypeMutableDictionary, // Property is an NSMutableDictionary
25+
CTCPropertyTypeUnsignedInteger, // Property is an NSUInteger
26+
CTCPropertyTypeDate, // Property is an NSDate
27+
CTCPropertyTypeDouble // Property is a double
3028
};
3129

3230
@interface CTCBaseModel ()
@@ -47,9 +45,23 @@ + (void)initialize {
4745

4846
dispatch_once(&onceToken, ^{
4947
modelProperties = [NSMutableDictionary dictionary];
50-
propertyTypesArray = kPropertyTypesArray;
48+
49+
// note this array's indexes MUST match the CTCPropertyType enum values for lookups to work properly
50+
propertyTypesArray = @[@"Unknown", // CTCPropertyUnknown
51+
@"NSString", // CTCPropertyTypeString
52+
[NSString stringWithFormat:@"%s",@encode(BOOL)], // CTCPropertyTypeBool
53+
@"NSNumber", // CTCPropertyTypeNumber
54+
[NSString stringWithFormat:@"%s",@encode(int)], // CTCPropertyTypeInteger
55+
[NSString stringWithFormat:@"%s",@encode(float)], // CTCPropertyTypeFloat
56+
@"NSArray", // CTCPropertyTypeArray
57+
@"NSMutableArray", // CTCPropertyTypeMutableArray
58+
@"NSDictionary", // CTCPropertyTypeDictionary
59+
@"NSMutableDictionary", // CTCPropertyTypeMutableDictionary
60+
[NSString stringWithFormat:@"%s",@encode(unsigned int)], // CTCPropertyTypeUnsignedInteger
61+
@"NSDate", // CTCPropertyTypeDate
62+
[NSString stringWithFormat:@"%s",@encode(double)]]; // CTCPropertyTypeDouble
5163
});
52-
64+
5365
NSMutableDictionary *translateNameDict = [NSMutableDictionary dictionary];
5466
[self hydrateModelProperties:[self class] translateDictionary:translateNameDict];
5567
[modelProperties setObject:translateNameDict forKey:[self calculateClassName]];

0 commit comments

Comments
 (0)