Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Configuring UITableViews with C99 array initialization!
// Define your table view's sections
typedef enum {
kTitleSection = 0,
} NESTemplateEditTableSections;
// Make configuration arrays indexed against table sections.
// It's safe to reorder the original enum!
static NSString * const kCellIdentifiers[kNumberOfSections] = {
[kTitleSection] = @"AccomplishmentTitleCell",
[kGoalSection] = @"AccomplishmentGoalCell"
static UITableViewCellSelectionStyle const kCellSelectionStyles[kNumberOfSections] = {
[kTitleSection] = UITableViewCellSelectionStyleNone,
[kGoalSection] = UITableViewCellSelectionStyleBlue
static UITableViewCellAccessoryType const kCellAccessoryTypes[kNumberOfSections] = {
[kGoalSection] = UITableViewCellAccessoryDisclosureIndicator
// If you can't initialize an array statically (like if you need localized strings),
// just initialize it separately.
static NSString *kLocalizedSectionTitles[kNumberOfSections];
__attribute__((constructor)) static void __InitLocalizedSectionTitles()
@autoreleasepool {
kLocalizedSectionTitles[kTitleSection] = NSLocalizedString(@"What have you accomplished?", nil);
kLocalizedSectionTitles[kGoalSection] = NSLocalizedString(@"Category", nil);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.