Extend ObjC class with Swift extension Causes crashes when released to Appstore

Hi

I have an objective project and when I'm extending the project to Swift It works fine when locally testing it and also when testing it over testflight.

But after submitting the app to the appstore and when users download it and use I see crash reports coming from the Sentry related with the swift extensions created over the objective-c class.

I'm unable to reproduce this locally.

Any Help would be appreciated.

Attached the crash report.

  • Can you elaborate a bit on the category you are adding? What is it doing? Is that method on the stack here somewhere? The crash log is not symbolicated it seems.

Add a Comment

Replies

Example Objective-C class

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.