Settings.h
#import <Foundation/Foundation.h>
@interface Settings : NSObject
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
- (BOOL)boolForKey:(NSString *)key;
@end
Settings.m
#import "Settings.h"
@implementation Settings {
NSDictionary *_dictionary;
}
- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
self = [super init];
if (self) {
_dictionary = dictionary;
}
return self;
}
- (BOOL)boolForKey:(NSString *)key {
return [[_dictionary objectForKey:key] boolValue];
}
@end
Swift extension
Settings+extension.swift
import Foundation
extension Settings {
@objc public func isFirstProperty() -> Bool {
return self.bool(forKey: "isFirstProperty")
}
@objc public func isSecondProperty() -> Bool {
return self.bool(forKey: "isSecondProperty")
}
}
Call example inside UICollectionViewController sub class
@implementation CollectionViewController {
Settings* _settings;
}
-(void)viewDidLoad {
[super viewDidLoad];
_settings = [[Settings alloc] initWithDictionary:someDictionary];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseIdentifier" forIndexPath:indexPath];
if ([_settings isFirstProperty]) {
//Do something with cell according to firstProperty
} else if ([_settings isSecondProperty]) {
//Do something with cell according to secondProperty
}
return cell;
}
@end
I tested the app, everything worked great. I uploaded the app to the App Store. Almost from the beginning of the use of the new application by users, I began to receive crash reports.