File tree Expand file tree Collapse file tree 3 files changed +30
-27
lines changed Expand file tree Collapse file tree 3 files changed +30
-27
lines changed Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ NS_SWIFT_NAME(Event)
181
181
/* *
182
182
* Init an @c SentryEvent will set all needed fields by default.
183
183
*/
184
- - (instancetype )init;
184
+ - (instancetype )init NS_DESIGNATED_INITIALIZER ;
185
185
186
186
/* *
187
187
* Init a @c SentryEvent with a @c SentryLevelError and set all needed fields by default.
@@ -196,24 +196,4 @@ NS_SWIFT_NAME(Event)
196
196
197
197
@end
198
198
199
- /* *
200
- * Subclass of SentryEvent so we can add the Decodable implementation via a Swift extension. We need
201
- * this due to our mixed use of public Swift and ObjC classes. We could avoid this class by
202
- * converting SentryReplayEvent back to ObjC, but we rather accept this tradeoff as we want to
203
- * convert all public classes to Swift in the future. This class needs to be public as we can't add
204
- * the Decodable extension implementation to a class that is not public.
205
- *
206
- * @note: We can’t add the extension for Decodable directly on SentryEvent, because we get an error
207
- * in SentryReplayEvent: 'required' initializer 'init(from:)' must be provided by subclass of
208
- * 'Event' Once we add the initializer with required convenience public init(from decoder: any
209
- * Decoder) throws { fatalError("init(from:) has not been implemented")
210
- * }
211
- * we get the error initializer 'init(from:)' is declared in extension of 'Event' and cannot be
212
- * overridden. Therefore, we add the Decodable implementation not on the Event, but to a subclass of
213
- * the event.
214
- */
215
- @interface SentryEventDecodable : SentryEvent
216
-
217
- @end
218
-
219
199
NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change 25
25
26
26
@implementation SentryEvent
27
27
28
+ // This is a designated initializer so that it can be called by the Swift
29
+ // sublcass that adds a `Decodable` conformance. It shares an implementation
30
+ // with `initWithLevel:`.
28
31
- (instancetype )init
29
32
{
30
- return [self initWithLevel: kSentryLevelNone ];
33
+ self = [super init ];
34
+ return [self commonInit: kSentryLevelNone ];
31
35
}
32
36
33
37
- (instancetype )initWithLevel : (enum SentryLevel)level
34
38
{
35
39
self = [super init ];
40
+ return [self commonInit: level];
41
+ }
42
+
43
+ - (instancetype )commonInit : (enum SentryLevel)level
44
+ {
36
45
if (self) {
37
46
self.eventId = [[SentryId alloc ] init ];
38
47
self.level = level;
@@ -210,8 +219,4 @@ - (BOOL)isAppHangEvent
210
219
211
220
@end
212
221
213
- @implementation SentryEventDecodable
214
-
215
- @end
216
-
217
222
NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change 1
1
@_implementationOnly import _SentryPrivate
2
2
import Foundation
3
3
4
- extension SentryEventDecodable : Decodable {
4
+ /**
5
+ * Subclass of SentryEvent so we can add the Decodable implementation via a Swift extension. We need
6
+ * this due to our mixed use of public Swift and ObjC classes. We could avoid this class by
7
+ * converting SentryReplayEvent back to ObjC, but we rather accept this tradeoff as we want to
8
+ * convert all public classes to Swift in the future. This does not need to be public, but was previously
9
+ * defined in objc and was public. In the next major version of the SDK we should make it `internal` and `final`
10
+ * and remove the `@objc` annotation.
11
+ *
12
+ * @note: We can’t add the extension for Decodable directly on SentryEvent, because we get an error
13
+ * in SentryReplayEvent: 'required' initializer 'init(from:)' must be provided by subclass of
14
+ * 'Event' Once we add the initializer with required convenience public init(from decoder: any
15
+ * Decoder) throws { fatalError("init(from:) has not been implemented")
16
+ * }
17
+ * we get the error initializer 'init(from:)' is declared in extension of 'Event' and cannot be
18
+ * overridden. Therefore, we add the Decodable implementation not on the Event, but to a subclass of
19
+ * the event.
20
+ */
21
+ @objc ( SentryEventDecodable)
22
+ public class SentryEventDecodable : Event , Decodable {
5
23
6
24
private enum CodingKeys : String , CodingKey {
7
25
case eventId = " event_id "
You can’t perform that action at this time.
0 commit comments