Skip to content

Commit

Permalink
feat: Deprecate LDUser related functionality (#238)
Browse files Browse the repository at this point in the history
LDUser functionality has been replaced with the more flexible LDContext
concept which all LaunchDarkly SDKs will support.

We retained LDUser through the first major release to aide with the
adoption transition, but as we near the next release, we need to alert
customers that support will be ending.
  • Loading branch information
keelerm84 authored Jul 21, 2023
1 parent fe6ac02 commit 9c3989e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions LaunchDarkly/LaunchDarkly/LDClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public class LDClient {

This LDUser will be converted into an LDContext, and the context specific version of this method will be called. See `identify(context:completion:)` for details.
*/
@available(*, deprecated, message: "Use identify(context:completion:)")
public func identify(user: LDUser, completion: (() -> Void)? = nil) {
switch user.toContext() {
case .failure(let error):
Expand Down Expand Up @@ -601,6 +602,7 @@ public class LDClient {

This LDUser will be converted into an LDContext, and the context specific version of this method will be called. See `start(config:context:completion:)` for details.
*/
@available(*, deprecated, message: "Use start(config:context:completion:)")
public static func start(config: LDConfig, user: LDUser? = nil, completion: (() -> Void)? = nil) {
switch user?.toContext() {
case nil:
Expand Down Expand Up @@ -664,6 +666,7 @@ public class LDClient {

This LDUser will be converted into an LDContext, and the context specific version of this method will be called. See `start(config:context:startWaitSeconds:completion:)` for details.
*/
@available(*, deprecated, message: "Use start(config:context:startWithSeconds:completion:)")
public static func start(config: LDConfig, user: LDUser? = nil, startWaitSeconds: TimeInterval, completion: ((_ timedOut: Bool) -> Void)? = nil) {
switch user?.toContext() {
case nil:
Expand Down
3 changes: 3 additions & 0 deletions LaunchDarkly/LaunchDarkly/Models/LDUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Foundation
The usage of LDUser is no longer recommended and is retained only to ease the adoption of the `LDContext` class. New
code using this SDK should make use of the `LDContextBuilder` to construct an equivalent `Kind.user` kind context.
*/
@available(*, deprecated, message: "Use LDContextBuilder to construct a context of kind 'user'")
public struct LDUser: Encodable, Equatable {

static let optionalAttributes = UserAttribute.BuiltIn.allBuiltIns.filter { $0.name != "key" && $0.name != "anonymous"}
Expand Down Expand Up @@ -217,6 +218,7 @@ public struct LDUser: Encodable, Equatable {
}

/// Class providing ObjC interoperability with the LDUser struct
@available(*, deprecated)
@objc final class LDUserWrapper: NSObject {
let wrapped: LDUser

Expand All @@ -226,4 +228,5 @@ public struct LDUser: Encodable, Equatable {
}
}

@available(*, deprecated)
extension LDUser: TypeIdentifying { }
1 change: 1 addition & 0 deletions LaunchDarkly/LaunchDarkly/Models/UserAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
reference guides [Setting user attributes](https://docs.launchdarkly.com/home/users/attributes) and
[Targeting users](https://docs.launchdarkly.com/home/flags/targeting-users).
*/
@available(*, deprecated)
public class UserAttribute: Equatable, Hashable {

/**
Expand Down
4 changes: 4 additions & 0 deletions LaunchDarkly/LaunchDarkly/ObjectiveC/ObjcLDClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public final class ObjcLDClient: NSObject {

This LDUser will be converted into an LDContext, and the context specific version of this method will be called. See `identify(context)` for details.
*/
@available(*, deprecated, message: "Use identify(context)")
@objc public func identify(user: ObjcLDUser) {
ldClient.identify(user: user.user, completion: nil)
}
Expand All @@ -144,6 +145,7 @@ public final class ObjcLDClient: NSObject {

This LDUser will be converted into an LDContext, and the context specific version of this method will be called. See `identify(context:completion:)` for details.
*/
@available(*, deprecated, message: "Use identify(context:completion:)")
@objc public func identify(user: ObjcLDUser, completion: (() -> Void)? = nil) {
ldClient.identify(user: user.user, completion: completion)
}
Expand Down Expand Up @@ -577,6 +579,7 @@ public final class ObjcLDClient: NSObject {

This LDUser will be converted into an LDContext, and the context specific version of this method will be called. See `start(configuration:context:completion:)` for details.
*/
@available(*, deprecated, message: "Use start(configuration:context:completion:)")
@objc public static func start(configuration: ObjcLDConfig, user: ObjcLDUser, completion: (() -> Void)? = nil) {
LDClient.start(config: configuration.config, user: user.user, completion: completion)
}
Expand All @@ -598,6 +601,7 @@ public final class ObjcLDClient: NSObject {

This LDUser will be converted into an LDContext, and the context specific version of this method will be called. See `start(configuration:context:startWaitSeconds:completion:)` for details.
*/
@available(*, deprecated, message: "Use start(configuration:context:startWaitSeconds:completion:)")
@objc public static func start(configuration: ObjcLDConfig, user: ObjcLDUser, startWaitSeconds: TimeInterval, completion: ((_ timedOut: Bool) -> Void)? = nil) {
LDClient.start(config: configuration.config, user: user.user, startWaitSeconds: startWaitSeconds, completion: completion)
}
Expand Down
1 change: 1 addition & 0 deletions LaunchDarkly/LaunchDarkly/ObjectiveC/ObjcLDUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Foundation
code using this SDK should make use of the `LDContextBuilder` to construct an equivalent `Kind.user` kind context.
*/
@objc (LDUser)
@available(*, deprecated, message: "Use ObjcLDContextBuilder to construct a context of kind 'user'")
public final class ObjcLDUser: NSObject {
var user: LDUser

Expand Down

0 comments on commit 9c3989e

Please sign in to comment.