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.
This is the code I'm using
Example Objective-C class
#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
Crash Report
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Crashed Thread: 0
Application Specific Information:
> customProperties
Thread 0 Crashed:
0 <unknown> 0x103087e44 <redacted>
1 <unknown> 0x102e1bbbc <redacted>
2 UIKitCore 0x185b6ff30 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:]
3 UIKitCore 0x185a68f44 -[UICollectionView _updateVisibleCellsNow:]
4 UIKitCore 0x1859bcb3c -[UICollectionView layoutSubviews]
5 UIKitCore 0x1859cf470 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
6 QuartzCore 0x187132790 CA::Layer::layout_if_needed
7 UIKitCore 0x185a33a18 -[UIView(Hierarchy) layoutBelowIfNeeded]
8 <unknown> 0x102e13e44 <redacted>
9 UIKitCore 0x1859c819c +[UIView _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:]
10 <unknown> 0x102e13ca0 <redacted>
11 <unknown> 0x102e14e3c <redacted>
12 <unknown> 0x102e16618 <redacted>
13 UIKitCore 0x185b52c00 -[UICollectionView _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:deselectPrevious:performCustomSelectionAction:]
14 UIKitCore 0x185eec844 -[UICollectionView touchesEnded:withEvent:]
15 UIKitCore 0x185a36dd0 [inlined] forwardTouchMethod
16 UIKitCore 0x185a36dd0 forwardTouchMethod
17 UIKitCore 0x1859a624c _UIGestureEnvironmentUpdate
18 UIKitCore 0x1859d8d88 -[UIGestureEnvironment _updateForEvent:window:]
19 UIKitCore 0x1859e5f28 -[UIWindow sendEvent:]
20 UIKitCore 0x185b95e30 -[UIApplication sendEvent:]
21 UIKitCore 0x1859b913c __dispatchPreprocessedEventFromEventQueue
22 UIKitCore 0x1859adf28 __processEventQueue
23 UIKitCore 0x1859b33d4 __eventFetcherSourceCallback
24 CoreFoundation 0x1834540cc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
25 CoreFoundation 0x183464d8c __CFRunLoopDoSource0
26 CoreFoundation 0x18339f094 __CFRunLoopDoSources0
27 CoreFoundation 0x1833a48a0 __CFRunLoopRun
28 CoreFoundation 0x1833b8464 CFRunLoopRunSpecific
29 GraphicsServices 0x19ef5c388 GSEventRunModal
30 UIKitCore 0x185d5b5cc -[UIApplication _run]
31 UIKitCore 0x185ad9f70 UIApplicationMain
32 <unknown> 0x102ff762c <redacted>
33 <unknown> 0x1034c5aa4 <redacted>