Skip to content

Commit c028abd

Browse files
committed
Convert SentryGeo to Swift
1 parent 603fec8 commit c028abd

File tree

9 files changed

+113
-180
lines changed

9 files changed

+113
-180
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
33EB2A912C3412E4004FED3D /* SentryWithoutUIKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 33EB2A8F2C3411AE004FED3D /* SentryWithoutUIKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
7878
33EB2A922C341300004FED3D /* Sentry.h in Headers */ = {isa = PBXBuildFile; fileRef = 63AA76931EB9C1C200D153DE /* Sentry.h */; settings = {ATTRIBUTES = (Public, ); }; };
7979
51B15F802BE88D510026A2F2 /* URLSessionTaskHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51B15F7F2BE88D510026A2F2 /* URLSessionTaskHelperTests.swift */; };
80-
620078722D38F00D0022CB67 /* SentryGeoCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620078712D38F00D0022CB67 /* SentryGeoCodable.swift */; };
8180
620078742D38F0DF0022CB67 /* SentryCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620078732D38F0DF0022CB67 /* SentryCodable.swift */; };
8281
620078782D3906BF0022CB67 /* SentryCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620078772D3906BF0022CB67 /* SentryCodableTests.swift */; };
8382
620379DB2AFE1415005AC0C1 /* SentryBuildAppStartSpans.h in Headers */ = {isa = PBXBuildFile; fileRef = 620379DA2AFE1415005AC0C1 /* SentryBuildAppStartSpans.h */; };
@@ -797,8 +796,6 @@
797796
925824C22CB5897700C9B20B /* SentrySessionReplayIntegration-Hybrid.h in Headers */ = {isa = PBXBuildFile; fileRef = D80382BE2C09C6FD0090E048 /* SentrySessionReplayIntegration-Hybrid.h */; settings = {ATTRIBUTES = (Private, ); }; };
798797
92672BB629C9A2A9006B021C /* SentryBreadcrumb+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 92672BB529C9A2A9006B021C /* SentryBreadcrumb+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
799798
927A5CC42DD7626B00B82404 /* SentryEnvelopeItemHeaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 927A5CC32DD7626400B82404 /* SentryEnvelopeItemHeaderTests.swift */; };
800-
9286059529A5096600F96038 /* SentryGeo.h in Headers */ = {isa = PBXBuildFile; fileRef = 9286059429A5096600F96038 /* SentryGeo.h */; settings = {ATTRIBUTES = (Public, ); }; };
801-
9286059729A5098900F96038 /* SentryGeo.m in Sources */ = {isa = PBXBuildFile; fileRef = 9286059629A5098900F96038 /* SentryGeo.m */; };
802799
9286059929A50BAB00F96038 /* SentryGeoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9286059829A50BAA00F96038 /* SentryGeoTests.swift */; };
803800
92E5F3D62CDBB3BF00B7AD98 /* SentrySampling.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E8C57A525EEFC42001CEEFA /* SentrySampling.h */; };
804801
92F6726B29C8B7B100BFD34D /* SentryUser+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 92F6726A29C8B7B000BFD34D /* SentryUser+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1062,8 +1059,9 @@
10621059
FA67DD182DDBD4EA00896B02 /* UIImageHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCED2DDBD4EA00896B02 /* UIImageHelper.swift */; };
10631060
FA67DD192DDBD4EA00896B02 /* SwizzleClassNameExclude.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCD52DDBD4EA00896B02 /* SwizzleClassNameExclude.swift */; };
10641061
FA8A36182DEAA1EB0058D883 /* SentryThread+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */; };
1065-
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
1062+
FA8DEC322DF7FB4100C25374 /* SentryGeo.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8DEC312DF7FB4100C25374 /* SentryGeo.swift */; };
10661063
FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */; };
1064+
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
10671065
/* End PBXBuildFile section */
10681066

10691067
/* Begin PBXContainerItemProxy section */
@@ -1218,7 +1216,6 @@
12181216
33C374BE2D104A41004598F1 /* SentrySdkPackage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySdkPackage.h; path = include/SentrySdkPackage.h; sourceTree = "<group>"; };
12191217
33EB2A8F2C3411AE004FED3D /* SentryWithoutUIKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryWithoutUIKit.h; path = Public/SentryWithoutUIKit.h; sourceTree = "<group>"; };
12201218
51B15F7F2BE88D510026A2F2 /* URLSessionTaskHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTaskHelperTests.swift; sourceTree = "<group>"; };
1221-
620078712D38F00D0022CB67 /* SentryGeoCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryGeoCodable.swift; sourceTree = "<group>"; };
12221219
620078732D38F0DF0022CB67 /* SentryCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCodable.swift; sourceTree = "<group>"; };
12231220
620078772D3906BF0022CB67 /* SentryCodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCodableTests.swift; sourceTree = "<group>"; };
12241221
620379DA2AFE1415005AC0C1 /* SentryBuildAppStartSpans.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryBuildAppStartSpans.h; path = include/SentryBuildAppStartSpans.h; sourceTree = "<group>"; };
@@ -2017,8 +2014,6 @@
20172014
92136D662C9D765D002A9FB8 /* SentryNSURLRequestBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSURLRequestBuilderTests.swift; sourceTree = "<group>"; };
20182015
92672BB529C9A2A9006B021C /* SentryBreadcrumb+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SentryBreadcrumb+Private.h"; path = "include/HybridPublic/SentryBreadcrumb+Private.h"; sourceTree = "<group>"; };
20192016
927A5CC32DD7626400B82404 /* SentryEnvelopeItemHeaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryEnvelopeItemHeaderTests.swift; sourceTree = "<group>"; };
2020-
9286059429A5096600F96038 /* SentryGeo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryGeo.h; path = Public/SentryGeo.h; sourceTree = "<group>"; };
2021-
9286059629A5098900F96038 /* SentryGeo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentryGeo.m; sourceTree = "<group>"; };
20222017
9286059829A50BAA00F96038 /* SentryGeoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryGeoTests.swift; sourceTree = "<group>"; };
20232018
92F6726A29C8B7B000BFD34D /* SentryUser+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SentryUser+Private.h"; path = "include/HybridPublic/SentryUser+Private.h"; sourceTree = "<group>"; };
20242019
A811D866248E2770008A41EA /* SentrySystemEventBreadcrumbsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySystemEventBreadcrumbsTest.swift; sourceTree = "<group>"; };
@@ -2304,6 +2299,7 @@
23042299
FA67DCEF2DDBD4EA00896B02 /* URLSessionTaskHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTaskHelper.swift; sourceTree = "<group>"; };
23052300
FA67DCF22DDBD4EA00896B02 /* SwiftDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDescriptor.swift; sourceTree = "<group>"; };
23062301
FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryThread+Private.h"; path = "include/SentryThread+Private.h"; sourceTree = "<group>"; };
2302+
FA8DEC312DF7FB4100C25374 /* SentryGeo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryGeo.swift; sourceTree = "<group>"; };
23072303
FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUserFeedback.swift; sourceTree = "<group>"; };
23082304
FAEC273C2DF3933200878871 /* NSData+Unzip.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Unzip.m"; sourceTree = "<group>"; };
23092305
FAEC273E2DF393E000878871 /* NSData+Unzip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+Unzip.h"; sourceTree = "<group>"; };
@@ -2402,14 +2398,14 @@
24022398
620078752D38F1110022CB67 /* Codable */ = {
24032399
isa = PBXGroup;
24042400
children = (
2401+
FA8DEC312DF7FB4100C25374 /* SentryGeo.swift */,
24052402
623FD9032D3FA90900803EDA /* NSNumberDecodableWrapper.swift */,
24062403
6281C5712D3E4F06009D0978 /* DecodeArbitraryData.swift */,
24072404
623FD9012D3FA5DA00803EDA /* SentryFrameCodable.swift */,
24082405
6293F5742D422A8A002BC3BD /* SentryStacktraceCodable.swift */,
24092406
62F70E922D4234B100634054 /* SentryMechanismMetaCodable.swift */,
24102407
62F70E942D423BCA00634054 /* SentryMechanismCodable.swift */,
24112408
620467AB2D3FFD1C0025F06C /* SentryNSErrorCodable.swift */,
2412-
620078712D38F00D0022CB67 /* SentryGeoCodable.swift */,
24132409
628094732D39584700B3F18B /* SentryUserCodable.swift */,
24142410
627C77882D50B6840055E966 /* SentryBreadcrumbCodable.swift */,
24152411
628308602D50ADAC00EAEF77 /* SentryRequestCodable.swift */,
@@ -2550,8 +2546,6 @@
25502546
843FB3212D0CD04D00558F18 /* SentryUserAccess.h */,
25512547
843FB3222D0CD04D00558F18 /* SentryUserAccess.m */,
25522548
92F6726A29C8B7B000BFD34D /* SentryUser+Private.h */,
2553-
9286059429A5096600F96038 /* SentryGeo.h */,
2554-
9286059629A5098900F96038 /* SentryGeo.m */,
25552549
63B818F71EC34639002FDF4C /* SentryDebugMeta.h */,
25562550
63B818F81EC34639002FDF4C /* SentryDebugMeta.m */,
25572551
6360850B1ED2AFE100E8599E /* SentryBreadcrumb.h */,
@@ -4881,7 +4875,6 @@
48814875
84A7890A2C0E9F6400FF0803 /* SentrySpan+Private.h in Headers */,
48824876
7BC5B6FA290BCDE500D99477 /* SentryHttpStatusCodeRange+Private.h in Headers */,
48834877
7B04A9AF24EAC02C00E710B1 /* SentryRetryAfterHeaderParser.h in Headers */,
4884-
9286059529A5096600F96038 /* SentryGeo.h in Headers */,
48854878
7B98D7BC25FB607300C5A389 /* SentryWatchdogTerminationTracker.h in Headers */,
48864879
7BA61CB9247BC57B00C130A8 /* SentryCrashDefaultBinaryImageProvider.h in Headers */,
48874880
8E4E7C7D25DAB287006AB9E2 /* SentryTracer.h in Headers */,
@@ -5309,7 +5302,6 @@
53095302
7BCFA71627D0BB50008C662C /* SentryANRTrackerV1.m in Sources */,
53105303
8459FCC02BD73EB20038E9C9 /* SentryProfilerSerialization.mm in Sources */,
53115304
63EED6C02237923600E02400 /* SentryOptions.m in Sources */,
5312-
620078722D38F00D0022CB67 /* SentryGeoCodable.swift in Sources */,
53135305
D8CB741B2947286500A5F964 /* SentryEnvelopeItemHeader.m in Sources */,
53145306
D8CB7417294724CC00A5F964 /* SentryEnvelopeAttachmentHeader.m in Sources */,
53155307
D84793262788737D00BE8E99 /* SentryByteCountFormatter.m in Sources */,
@@ -5386,6 +5378,7 @@
53865378
6360850E1ED2AFE100E8599E /* SentryBreadcrumb.m in Sources */,
53875379
D82859432C3E753C009A28AA /* SentrySessionReplaySyncC.c in Sources */,
53885380
D833D57C2D10784800961E7A /* SentryRRWebOptionsEvent.swift in Sources */,
5381+
FA8DEC322DF7FB4100C25374 /* SentryGeo.swift in Sources */,
53895382
84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */,
53905383
7B56D73324616D9500B842DA /* SentryConcurrentRateLimitsDictionary.m in Sources */,
53915384
8ECC674825C23A20000E2BF6 /* SentryTransaction.m in Sources */,
@@ -5528,7 +5521,6 @@
55285521
7B98D7CF25FB650F00C5A389 /* SentryWatchdogTerminationTrackingIntegration.m in Sources */,
55295522
8E5D38DD261D4A3E000D363D /* SentryPerformanceTrackingIntegration.m in Sources */,
55305523
7B4E23C2251A2C2B00060D68 /* SentryCrashIntegrationSessionHandler.m in Sources */,
5531-
9286059729A5098900F96038 /* SentryGeo.m in Sources */,
55325524
D43B26D82D70A550007747FD /* SentryTraceOrigin.m in Sources */,
55335525
D8A3649C2C91AA3300AC569B /* SentryReplayApi.m in Sources */,
55345526
7B42C48227E08F4B009B58C2 /* SentryDependencyContainer.m in Sources */,

Sources/Sentry/Public/Sentry.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[];
2222
# import <Sentry/SentryException.h>
2323
# import <Sentry/SentryFeedbackAPI.h>
2424
# import <Sentry/SentryFrame.h>
25-
# import <Sentry/SentryGeo.h>
2625
# import <Sentry/SentryHttpStatusCodeRange.h>
2726
# import <Sentry/SentryHub.h>
2827
# import <Sentry/SentryIntegrationProtocol.h>

Sources/Sentry/Public/SentryGeo.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

Sources/Sentry/Public/SentrySerializable.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99

1010
NS_ASSUME_NONNULL_BEGIN
1111

12-
@protocol SentrySerializable <NSObject>
13-
SENTRY_NO_INIT
12+
// ObjC allows you to define a new -init
13+
// event when the class conforms to a protocol
14+
// using `SENTRY_NO_INIT`, but Swift is more strict
15+
// about this. When migrating an ObjC `SentrySerializable`
16+
// class that had used this method into Swift, conform to
17+
// SentrySerializableBase instead to keep the behavior.
18+
@protocol SentrySerializableBase <NSObject>
1419

1520
/**
1621
* Serialize the contents of the object into an NSDictionary. Make to copy all properties of the
@@ -20,4 +25,8 @@ SENTRY_NO_INIT
2025

2126
@end
2227

28+
@protocol SentrySerializable <SentrySerializableBase>
29+
SENTRY_NO_INIT
30+
@end
31+
2332
NS_ASSUME_NONNULL_END

Sources/Sentry/Public/SentryWithoutUIKit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[];
2323
# import <SentryWithoutUIKit/SentryException.h>
2424
# import <SentryWithoutUIKit/SentryFeedbackAPI.h>
2525
# import <SentryWithoutUIKit/SentryFrame.h>
26-
# import <SentryWithoutUIKit/SentryGeo.h>
2726
# import <SentryWithoutUIKit/SentryHttpStatusCodeRange.h>
2827
# import <SentryWithoutUIKit/SentryHub.h>
2928
# import <SentryWithoutUIKit/SentryIntegrationProtocol.h>

Sources/Sentry/SentryGeo.m

Lines changed: 0 additions & 93 deletions
This file was deleted.

Sources/Sentry/SentryUser.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#import "SentryUser.h"
2-
#import "SentryGeo.h"
32
#import "SentryNSDictionarySanitize.h"
3+
#import "SentrySwift.h"
44

55
NS_ASSUME_NONNULL_BEGIN
66

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import Foundation
2+
3+
/// Approximate geographical location of the end user or device.
4+
///
5+
/// Example of serialized data:
6+
/// {
7+
/// "geo": {
8+
/// "country_code": "US",
9+
/// "city": "Ashburn",
10+
/// "region": "San Francisco"
11+
/// }
12+
/// }
13+
@objc(SentryGeo)
14+
@objcMembers
15+
open class Geo: NSObject, SentrySerializableBase, NSCopying, Decodable {
16+
17+
private enum CodingKeys: String, CodingKey {
18+
case city
19+
case countryCode = "country_code"
20+
case region
21+
}
22+
23+
/// Optional: Human readable city name.
24+
open var city: String?
25+
26+
/// Optional: Two-letter country code (ISO 3166-1 alpha-2).
27+
open var countryCode: String?
28+
29+
/// Optional: Human readable region name or code.
30+
open var region: String?
31+
32+
required public init(from decoder: Decoder) throws {
33+
super.init()
34+
let container = try decoder.container(keyedBy: CodingKeys.self)
35+
36+
self.city = try container.decodeIfPresent(String.self, forKey: .city)
37+
self.countryCode = try container.decodeIfPresent(String.self, forKey: .countryCode)
38+
self.region = try container.decodeIfPresent(String.self, forKey: .region)
39+
}
40+
41+
override init() {
42+
super.init()
43+
}
44+
45+
public func copy(with zone: NSZone? = nil) -> Any {
46+
let copy = Geo()
47+
copy.city = self.city
48+
copy.countryCode = self.countryCode
49+
copy.region = self.region
50+
return copy
51+
}
52+
53+
public func serialize() -> [String: Any] {
54+
var serializedData = [String: Any]()
55+
56+
if let city = self.city {
57+
serializedData["city"] = city
58+
}
59+
60+
if let countryCode = self.countryCode {
61+
serializedData["country_code"] = countryCode
62+
}
63+
64+
if let region = self.region {
65+
serializedData["region"] = region
66+
}
67+
68+
return serializedData
69+
}
70+
71+
public override func isEqual(_ object: Any?) -> Bool {
72+
guard let other = object as? Geo else {
73+
return false
74+
}
75+
76+
return isEqualToGeo(other)
77+
}
78+
79+
public func isEqualToGeo(_ geo: Geo) -> Bool {
80+
if self === geo {
81+
return true
82+
}
83+
84+
return self.city == geo.city &&
85+
self.countryCode == geo.countryCode &&
86+
self.region == geo.region
87+
}
88+
89+
public override var hash: Int {
90+
var hasher = Hasher()
91+
hasher.combine(city)
92+
hasher.combine(countryCode)
93+
hasher.combine(region)
94+
return hasher.finalize()
95+
}
96+
}

0 commit comments

Comments
 (0)