Skip to content

Commit

Permalink
refactoring names
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin committed Nov 21, 2022
1 parent 58ec104 commit 970b026
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 53 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

This version adds a dependency on Swift.

### Breaking Changes

- Make public APIs Swift friendly (#)
- Renamed `SentrySDK.addBreadcrumb(crumb:)` to `SentrySDK.addBreadcrumb(_ crumb:)`
- Renamed `SentryClient.add(_ crumb:)` to `SentryClient.addBreadcrumb(_ crumb:)`
- Renamed `SentryClient.add(_ attachment:)` to `SentryClient.addAttachment(_ attachment:)`
- Renamed `SentryClient.apply(to:)` to `SentryClient.applyTo(session:)`
- Renamed `SentryClient.apply(to:maxBreadcrumb:)` to `SentryClient.applyTo(event:maxBreadcrumbs:)`

### Features

- Properly demangle Swift class name (#2162)
Expand Down
4 changes: 2 additions & 2 deletions Samples/iOS-Swift/iOS-Swift/Tools/MetricKitManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MetricKitManager: NSObject, MXMetricManagerSubscriber {
}

SentrySDK.capture(message: "MetricKit received MXMetricPayload.") { scope in
attachments.forEach { scope.add($0) }
attachments.forEach { scope.addAttachment($0) }
}
}

Expand All @@ -34,7 +34,7 @@ class MetricKitManager: NSObject, MXMetricManagerSubscriber {
}

SentrySDK.capture(message: "MetricKit received MXDiagnosticPayload.") { scope in
attachments.forEach { scope.add($0) }
attachments.forEach { scope.addAttachment($0) }
}
}
}
6 changes: 3 additions & 3 deletions Samples/iOS-Swift/iOS-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class ViewController: UIViewController {
scope.setUser(user)

if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
scope.add(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
scope.addAttachment(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
}
if let data = "hello".data(using: .utf8) {
scope.add(Attachment(data: data, filename: "log.txt"))
scope.addAttachment(Attachment(data: data, filename: "log.txt"))
}
}

Expand Down Expand Up @@ -75,7 +75,7 @@ class ViewController: UIViewController {
let crumb = Breadcrumb(level: SentryLevel.info, category: "Debug")
crumb.message = "tapped addBreadcrumb"
crumb.type = "user"
SentrySDK.addBreadcrumb(crumb: crumb)
SentrySDK.addBreadcrumb(crumb)
}

@IBAction func captureMessage(_ sender: Any) {
Expand Down
2 changes: 1 addition & 1 deletion Samples/iOS-SwiftUI/iOS-SwiftUI/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct ContentView: View {
let crumb = Breadcrumb(level: SentryLevel.info, category: "Debug")
crumb.message = "tapped addBreadcrumb"
crumb.type = "user"
SentrySDK.addBreadcrumb(crumb: crumb)
SentrySDK.addBreadcrumb(crumb)
}

var captureMessageAction: () -> Void = {
Expand Down
4 changes: 2 additions & 2 deletions Samples/macOS-Swift/macOS-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {

SentrySDK.configureScope { scope in
if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
scope.add(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
scope.addAttachment(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
}

if let data = "hello".data(using: .utf8) {
scope.add(Attachment(data: data, filename: "log.txt"))
scope.addAttachment(Attachment(data: data, filename: "log.txt"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Samples/macOS-Swift/macOS-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ViewController: NSViewController {
let crumb = Breadcrumb(level: SentryLevel.info, category: "Debug")
crumb.message = "tapped addBreadcrumb"
crumb.type = "user"
SentrySDK.addBreadcrumb(crumb: crumb)
SentrySDK.addBreadcrumb(crumb)
}

@IBAction func captureMessage(_ sender: Any) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/Public/SentrySDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ SENTRY_NO_INIT
*
* @param crumb The Breadcrumb to add to the current Scope of the current Hub.
*/
+ (void)addBreadcrumb:(SentryBreadcrumb *)crumb NS_SWIFT_NAME(addBreadcrumb(crumb:));
+ (void)addBreadcrumb:(SentryBreadcrumb *)crumb NS_SWIFT_NAME(addBreadcrumb(_:));

/**
* Use this method to modify the current Scope of the current Hub. The SDK uses the Scope to attach
Expand All @@ -284,7 +284,7 @@ SENTRY_NO_INIT
*
* @param user The user to set to the current Scope.
*/
+ (void)setUser:(SentryUser *_Nullable)user;
+ (void)setUser:(nullable SentryUser *)user;

/**
* Starts a new SentrySession. If there's a running SentrySession, it ends it before starting the
Expand Down
12 changes: 7 additions & 5 deletions Sources/Sentry/Public/SentryScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ NS_SWIFT_NAME(Scope)
/**
* Add a breadcrumb to the scope
*/
- (void)addBreadcrumb:(SentryBreadcrumb *)crumb;
- (void)addBreadcrumb:(SentryBreadcrumb *)crumb NS_SWIFT_NAME(addBreadcrumb(_:));
;

/**
* Clears all breadcrumbs in the scope
Expand All @@ -103,10 +104,11 @@ NS_SWIFT_NAME(Scope)
/**
* Adds the Scope to the event
*/
- (SentryEvent *__nullable)applyToEvent:(SentryEvent *)event
maxBreadcrumb:(NSUInteger)maxBreadcrumbs;
- (nullable SentryEvent *)applyToEvent:(SentryEvent *)event
maxBreadcrumb:(NSUInteger)maxBreadcrumbs
NS_SWIFT_NAME(applyTo(event:maxBreadcrumbs:));

- (void)applyToSession:(SentrySession *)session;
- (void)applyToSession:(SentrySession *)session NS_SWIFT_NAME(applyTo(session:));

/**
* Sets context values which will overwrite SentryEvent.context when event is
Expand All @@ -126,7 +128,7 @@ NS_SWIFT_NAME(Scope)
*
* @param attachment The attachment to add to the Scope's list of attachments.
*/
- (void)addAttachment:(SentryAttachment *)attachment;
- (void)addAttachment:(SentryAttachment *)attachment NS_SWIFT_NAME(addAttachment(_:));

/**
* Clears all attachments in the scope.
Expand Down
4 changes: 2 additions & 2 deletions Tests/SentryTests/Protocol/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ class TestData {

let crumb1 = TestData.crumb
crumb1.message = "Crumb 1"
scope.add(crumb1)
scope.addBreadcrumb(crumb1)

let crumb2 = TestData.crumb
crumb2.message = "Crumb 2"
scope.add(crumb2)
scope.addBreadcrumb(crumb2)

return scope
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/SentryClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SentryClientTest: XCTestCase {
let scope = Scope()
scope.setEnvironment(environment)
scope.setTag(value: "value", key: "key")
scope.add(TestData.dataAttachment)
scope.addAttachment(TestData.dataAttachment)
scope.setContext(value: [SentryDeviceContextFreeMemoryKey: 2_000], key: "device")
return scope
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/SentryTests/SentryHubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SentryHubTests: XCTestCase {
options = Options()
options.dsn = SentryHubTests.dsnAsString

scope.add(crumb)
scope.addBreadcrumb(crumb)

event = Event()
event.message = SentryMessage(formatted: message)
Expand Down Expand Up @@ -661,7 +661,7 @@ class SentryHubTests: XCTestCase {

private func addBreadcrumbThroughConfigureScope(_ hub: SentryHub) {
hub.configureScope({ scope in
scope.add(self.fixture.crumb)
scope.addBreadcrumb(self.fixture.crumb)
})
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/SentryTests/SentrySDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SentrySDKTests: XCTestCase {
options.maxBreadcrumbs = 0
}

SentrySDK.addBreadcrumb(crumb: Breadcrumb(level: SentryLevel.warning, category: "test"))
SentrySDK.addBreadcrumb(Breadcrumb(level: SentryLevel.warning, category: "test"))
let breadcrumbs = Dynamic(SentrySDK.currentHub().scope).breadcrumbArray as [Breadcrumb]?
XCTAssertEqual(0, breadcrumbs?.count)
}
Expand Down Expand Up @@ -332,7 +332,7 @@ class SentrySDKTests: XCTestCase {
SentrySDK.setUser(user)

let actualScope = SentrySDK.currentHub().scope
let event = actualScope.apply(to: fixture.event, maxBreadcrumb: 10)
let event = actualScope.applyTo(event: fixture.event, maxBreadcrumbs: 10)
XCTAssertEqual(event?.user, user)
}

Expand Down
Loading

0 comments on commit 970b026

Please sign in to comment.