Skip to content

Commit f06446b

Browse files
committed
Optimized return types of instantiation methods.
1 parent cc207e2 commit f06446b

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

OSReflectionKit+CoreData/NSManagedObject+OSReflectionKit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
@return The instance of the created object
4646
@see -objectFromDictionary:
4747
*/
48-
+ (id) objectWithController:(NSFetchedResultsController *) controller;
48+
+ (instancetype) objectWithController:(NSFetchedResultsController *) controller;
4949

5050
/**
5151
Creates an instance from the type of the calling class and sets its properties from a `NSDictionay` object.
@@ -55,7 +55,7 @@
5555
@discussion If you have a class that has a property: `NSString` *name, then you can call [CustomClassName objectFromDictionay:@{@"name" : @"Alexandre Santos"}] and it will return an object of the type 'CustomClassName' with the attribute 'name' containing the value 'Alexandre Santos'.
5656
@see -object
5757
*/
58-
+ (id) objectFromDictionary:(NSDictionary *) dictionary withController:(NSFetchedResultsController *) controller;
58+
+ (instancetype) objectFromDictionary:(NSDictionary *) dictionary withController:(NSFetchedResultsController *) controller;
5959

6060
/**
6161
Creates a `NSArray` instance from the type of the calling class and sets its properties from an array of `NSDictionay` objects.
@@ -76,8 +76,8 @@
7676
@discussion If you have a class that has a property: `NSString` *name, then you can call [CustomClassName objectFromJSON:@"{"name" : "Alexandre Santos"}"] and it will return an object of the type 'CustomClassName' with the attribute 'name' containing the value 'Alexandre Santos'.
7777
@see -objectFromDictionary:
7878
*/
79-
+ (id) objectFromJSON:(NSString *) jsonString withController:(NSFetchedResultsController *) controller error:(NSError **) error;
80-
+ (id) objectFromJSON:(NSString *) jsonString withController:(NSFetchedResultsController *) controller;
79+
+ (instancetype) objectFromJSON:(NSString *) jsonString withController:(NSFetchedResultsController *) controller error:(NSError **) error;
80+
+ (instancetype) objectFromJSON:(NSString *) jsonString withController:(NSFetchedResultsController *) controller;
8181

8282
/**
8383
Creates a `NSArray` instance from the type of the calling class and sets its properties from an array of JSON objects.

OSReflectionKit+CoreData/NSManagedObject+OSReflectionKit.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ @implementation NSManagedObject (OSReflectionKit)
1212

1313
#pragma mark - Instanciation Methods
1414

15-
+ (id) objectWithController:(NSFetchedResultsController *) controller
15+
+ (instancetype) objectWithController:(NSFetchedResultsController *) controller
1616
{
1717
NSManagedObjectContext *context = [controller managedObjectContext];
1818
NSEntityDescription *entity = [[controller fetchRequest] entity];
@@ -22,7 +22,7 @@ + (id) objectWithController:(NSFetchedResultsController *) controller
2222
return newManagedObject;
2323
}
2424

25-
+ (id) objectFromDictionary:(NSDictionary *) dictionary withController:(NSFetchedResultsController *) controller
25+
+ (instancetype) objectFromDictionary:(NSDictionary *) dictionary withController:(NSFetchedResultsController *) controller
2626
{
2727
id object = [self objectWithController:controller];
2828

@@ -49,12 +49,12 @@ + (NSArray *) objectsFromDicts:(NSArray *) dicts withController:(NSFetchedResult
4949
return [objects copy];
5050
}
5151

52-
+ (id) objectFromJSON:(NSString *)jsonString withController:(NSFetchedResultsController *) controller
52+
+ (instancetype) objectFromJSON:(NSString *)jsonString withController:(NSFetchedResultsController *) controller
5353
{
5454
return [self objectFromJSON:jsonString withController:controller error:nil];
5555
}
5656

57-
+ (id)objectFromJSON:(NSString *)jsonString withController:(NSFetchedResultsController *) controller error:(NSError **)error
57+
+ (instancetype)objectFromJSON:(NSString *)jsonString withController:(NSFetchedResultsController *) controller error:(NSError **)error
5858
{
5959
// Convert the JSON text into a dictionary object
6060
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];

OSReflectionKit/NSObject+OSReflectionKit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
@return The instance of the created object
4848
@see -objectFromDictionary:
4949
*/
50-
+ (id) object;
50+
+ (instancetype) object;
5151

5252
/**
5353
Creates an instance from the type of the calling class and sets its properties from a `NSDictionay` object.
@@ -57,7 +57,7 @@
5757
@discussion If you have a class that has a property: `NSString` *name, then you can call [CustomClassName objectFromDictionay:@{@"name" : @"Alexandre Santos"}] and it will return an object of the type 'CustomClassName' with the attribute 'name' containing the value 'Alexandre Santos'.
5858
@see -object
5959
*/
60-
+ (id) objectFromDictionary:(NSDictionary *) dictionary;
60+
+ (instancetype) objectFromDictionary:(NSDictionary *) dictionary;
6161

6262
/**
6363
Creates a `NSArray` instance from the type of the calling class and sets its properties from an array of `NSDictionay` objects.
@@ -78,8 +78,8 @@
7878
@discussion If you have a class that has a property: `NSString` *name, then you can call [CustomClassName objectFromJSON:@"{"name" : "Alexandre Santos"}"] and it will return an object of the type 'CustomClassName' with the attribute 'name' containing the value 'Alexandre Santos'.
7979
@see -objectFromDictionary:
8080
*/
81-
+ (id) objectFromJSON:(NSString *) jsonString error:(NSError **) error;
82-
+ (id) objectFromJSON:(NSString *) jsonString;
81+
+ (instancetype) objectFromJSON:(NSString *) jsonString error:(NSError **) error;
82+
+ (instancetype) objectFromJSON:(NSString *) jsonString;
8383

8484
/**
8585
Creates a `NSArray` instance from the type of the calling class and sets its properties from an array of JSON objects.

OSReflectionKit/NSObject+OSReflectionKit.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ @implementation NSObject (OSReflectionKit)
1414

1515
#pragma mark - Instanciation Methods
1616

17-
+ (id) object
17+
+ (instancetype) object
1818
{
1919
return [[self alloc] init];
2020
}
@@ -38,12 +38,12 @@ + (NSArray *) objectsFromDicts:(NSArray *) dicts
3838
return [objects copy];
3939
}
4040

41-
+ (id) objectFromJSON:(NSString *)jsonString
41+
+ (instancetype) objectFromJSON:(NSString *)jsonString
4242
{
4343
return [self objectFromJSON:jsonString error:nil];
4444
}
4545

46-
+ (id)objectFromJSON:(NSString *)jsonString error:(NSError **)error
46+
+ (instancetype)objectFromJSON:(NSString *)jsonString error:(NSError **)error
4747
{
4848
// Convert the JSON text into a dictionary object
4949
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];

OSReflectionKitExample/FlipsideViewController.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@interface FlipsideViewController ()
2020

2121
@property (nonatomic, strong) NSArray *profilePropertyNames;
22+
@property (nonatomic, strong) NSArray *addressPropertyNames;
2223

2324
@end
2425

@@ -39,6 +40,7 @@ - (void)viewDidLoad
3940
NSMutableArray *allProperties = [[Profile propertyNames] mutableCopy];
4041
[allProperties removeObjectsInArray:@[@"address", @"hobbies"]];
4142
self.profilePropertyNames = allProperties;
43+
self.addressPropertyNames = [Address propertyNames];
4244
}
4345

4446
- (void)didReceiveMemoryWarning
@@ -74,7 +76,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
7476

7577
case SECTION_PROFILE_ADDRESS:
7678
// All properties for the address
77-
numberOfRows = [[[self.profile.address class] propertyNames] count];
79+
numberOfRows = [self.addressPropertyNames count];
7880
break;
7981

8082
case SECTION_PROFILE_HOBBIES:
@@ -126,7 +128,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
126128
cell = [tableView dequeueReusableCellWithIdentifier:@"CellDetailID"];
127129

128130
Address *address = self.profile.address;
129-
NSString *propertyName = [[Address propertyNames] objectAtIndex:indexPath.row];
131+
NSString *propertyName = [self.addressPropertyNames objectAtIndex:indexPath.row];
130132
cell.textLabel.text = [propertyName capitalizedString];
131133
cell.detailTextLabel.text = [address valueForKey:propertyName];
132134
}

OSReflectionKitExample/OSReflectionKitExample-Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<array>
3333
<string>armv7</string>
3434
</array>
35+
<key>UIStatusBarStyle</key>
36+
<string>UIStatusBarStyleBlackOpaque</string>
3537
<key>UIStatusBarTintParameters</key>
3638
<dict>
3739
<key>UINavigationBar</key>

0 commit comments

Comments
 (0)