Skip to content

Instantly share code, notes, and snippets.

@jonfriskics
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonfriskics/11373716 to your computer and use it in GitHub Desktop.
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
#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