Last active
August 29, 2015 14:00
-
-
Save jonfriskics/11373716 to your computer and use it in GitHub Desktop.
Making NSArray.count not throw an implicit signedness error when calling the tableView:numberOfRowsInSection: method
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 "TableViewController.h" | |
@interface NSArray (CountForTableView) | |
- (NSInteger)countForTableView; | |
@end | |
@implementation NSArray (CountForTableView) | |
- (NSInteger)countForTableView | |
{ | |
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 | |
return (long)[self count]; | |
#else | |
return (int)[self count]; | |
#endif | |
} | |
@end | |
@interface TableViewController () | |
@property (strong, nonatomic) NSArray *dataSource; | |
@end | |
@implementation TableViewController | |
#pragma mark - Table view data source | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView | |
{ | |
return self.dataSource.countForTableView; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | |
{ | |
return 1; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment