Skip to content

Commit

Permalink
refactor: Refactor MPUserAttributeChange to Swift (#317)
Browse files Browse the repository at this point in the history
* refactor: Refactor MPUserAttributeChange to Swift

* Simplify logic on Zoom pairing session with Brandon

---------

Co-authored-by: Ben Baron <[email protected]>
  • Loading branch information
BrandonStalnaker and einsteinx2 authored Dec 11, 2024
1 parent 07c96ca commit 488c9e3
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 96 deletions.
4 changes: 2 additions & 2 deletions UnitTests/MPMessageBuilderTests.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "MPMessageBuilder.h"
#import "mParticle.h"
#import "MPIConstants.h"
#import "MPSession.h"
#import "MPMessage.h"
Expand All @@ -13,9 +14,8 @@
#import "MPCommerceEvent.h"
#import "MPCommerceEvent+Dictionary.h"
#import "NSDictionary+MPCaseInsensitive.h"
#import "MPUserAttributeChange.h"
#import "MParticleSwift.h"
#import "MPPersistenceController.h"
#import "mParticle.h"
#import "MPBaseTestCase.h"
#import "MPStateMachine.h"
#import "MParticleReachability.h"
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/MPUserAttributeChangeTests.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <XCTest/XCTest.h>
#import "MPUserAttributeChange.h"
#import "MParticleSwift.h"
#import "MPBaseTestCase.h"

@interface MPUserAttributeChangeTests : MPBaseTestCase
Expand Down Expand Up @@ -34,7 +34,7 @@ - (void)testInstance {
XCTAssertNil(userAttributeChange.timestamp);
XCTAssertEqualObjects(userAttributeChange.userAttributes, userAttributes);
XCTAssertNil(userAttributeChange.value);
XCTAssertEqualObjects(userAttributeChange.valueToLog, [NSNull null]);
XCTAssertNil(userAttributeChange.valueToLog);
XCTAssertTrue(userAttributeChange.changed);
XCTAssertTrue(userAttributeChange.deleted);
XCTAssertTrue(userAttributeChange.isArray);
Expand Down
18 changes: 6 additions & 12 deletions mParticle-Apple-SDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
531BCF372B28A23400F5C573 /* MPIdentityCaching.m in Sources */ = {isa = PBXBuildFile; fileRef = 531BCF332B28A23400F5C573 /* MPIdentityCaching.m */; };
531BCF3A2B28A83E00F5C573 /* MPIdentityCachingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 531BCF392B28A83E00F5C573 /* MPIdentityCachingTests.m */; };
531BCF3B2B28A83E00F5C573 /* MPIdentityCachingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 531BCF392B28A83E00F5C573 /* MPIdentityCachingTests.m */; };
534C11B62D08F53D00466F71 /* MPUserAttributeChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 534C11B52D08F53D00466F71 /* MPUserAttributeChange.swift */; };
534C11B72D08F53D00466F71 /* MPUserAttributeChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 534C11B52D08F53D00466F71 /* MPUserAttributeChange.swift */; };
534CD25C29CE2877008452B3 /* NSNumber+MPFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2629CDFB1F00E7489F /* NSNumber+MPFormatter.swift */; };
534CD25E29CE2BF1008452B3 /* MParticleSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 534CD25D29CE2BF1008452B3 /* MParticleSwift.h */; };
534CD25F29CE2BF1008452B3 /* MParticleSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 534CD25D29CE2BF1008452B3 /* MParticleSwift.h */; };
Expand Down Expand Up @@ -160,14 +162,12 @@
53A79BDA29CDFB2000E7489F /* MPDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1529CDFB1F00E7489F /* MPDevice.m */; };
53A79BDB29CDFB2000E7489F /* MParticleWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1629CDFB1F00E7489F /* MParticleWebView.h */; };
53A79BDC29CDFB2000E7489F /* MPLaunchInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1729CDFB1F00E7489F /* MPLaunchInfo.h */; };
53A79BDE29CDFB2000E7489F /* MPUserAttributeChange.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1929CDFB1F00E7489F /* MPUserAttributeChange.h */; };
53A79BDF29CDFB2000E7489F /* MPMessageBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */; };
53A79BE229CDFB2000E7489F /* MPIUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */; };
53A79BE329CDFB2000E7489F /* MPBracket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */; };
53A79BE829CDFB2000E7489F /* MPUploadBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */; };
53A79BE929CDFB2000E7489F /* MPApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2429CDFB1F00E7489F /* MPApplication.h */; settings = {ATTRIBUTES = (Public, ); }; };
53A79BEB29CDFB2000E7489F /* NSNumber+MPFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2629CDFB1F00E7489F /* NSNumber+MPFormatter.swift */; };
53A79BEC29CDFB2000E7489F /* MPUserAttributeChange.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2729CDFB1F00E7489F /* MPUserAttributeChange.m */; };
53A79BEE29CDFB2000E7489F /* MPLaunchInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2929CDFB1F00E7489F /* MPLaunchInfo.m */; };
53A79BEF29CDFB2000E7489F /* MParticleWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2A29CDFB1F00E7489F /* MParticleWebView.m */; };
53A79BF029CDFB2000E7489F /* MPDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B2B29CDFB1F00E7489F /* MPDevice.h */; };
Expand Down Expand Up @@ -382,7 +382,6 @@
53A79D5129CE23F700E7489F /* MParticleReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B0029CDFB1F00E7489F /* MParticleReachability.h */; };
53A79D5329CE23F700E7489F /* MPCustomModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B3029CDFB1F00E7489F /* MPCustomModule.h */; };
53A79D5529CE23F700E7489F /* MPPersistenceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */; };
53A79D5729CE23F700E7489F /* MPUserAttributeChange.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1929CDFB1F00E7489F /* MPUserAttributeChange.h */; };
53A79D5829CE23F700E7489F /* MPIdentityDTO.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AA029CDFB1E00E7489F /* MPIdentityDTO.h */; };
53A79D5929CE23F700E7489F /* MPMessageBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */; };
53A79D5A29CE23F700E7489F /* MPURLRequestBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 53A79AA829CDFB1E00E7489F /* MPURLRequestBuilder.h */; };
Expand Down Expand Up @@ -466,7 +465,6 @@
53A79DB929CE23F700E7489F /* MPKitContainer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B5029CDFB1F00E7489F /* MPKitContainer.mm */; };
53A79DBA29CE23F700E7489F /* MPUploadBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */; };
53A79DBC29CE23F700E7489F /* MPBaseProjection.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B5329CDFB1F00E7489F /* MPBaseProjection.m */; };
53A79DBE29CE23F700E7489F /* MPUserAttributeChange.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B2729CDFB1F00E7489F /* MPUserAttributeChange.m */; };
53A79DBF29CE23F700E7489F /* MPIdentityApiManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AA229CDFB1E00E7489F /* MPIdentityApiManager.m */; };
53B28FB22C938C26009072FC /* MPLocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53B28FB12C938C26009072FC /* MPLocationManager.swift */; };
53B28FB32C938C26009072FC /* MPLocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53B28FB12C938C26009072FC /* MPLocationManager.swift */; };
Expand Down Expand Up @@ -529,6 +527,7 @@
531BCF322B28A23400F5C573 /* MPIdentityCaching.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPIdentityCaching.h; sourceTree = "<group>"; };
531BCF332B28A23400F5C573 /* MPIdentityCaching.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPIdentityCaching.m; sourceTree = "<group>"; };
531BCF392B28A83E00F5C573 /* MPIdentityCachingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPIdentityCachingTests.m; sourceTree = "<group>"; };
534C11B52D08F53D00466F71 /* MPUserAttributeChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPUserAttributeChange.swift; sourceTree = "<group>"; };
534CD25D29CE2BF1008452B3 /* MParticleSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MParticleSwift.h; sourceTree = "<group>"; };
534CD2AA29CE2CE1008452B3 /* mParticle-Apple-SDK-NoLocationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "mParticle-Apple-SDK-NoLocationTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
5399DDB72CA727E1006526E1 /* MPZip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPZip.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -603,14 +602,12 @@
53A79B1529CDFB1F00E7489F /* MPDevice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDevice.m; sourceTree = "<group>"; };
53A79B1629CDFB1F00E7489F /* MParticleWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MParticleWebView.h; sourceTree = "<group>"; };
53A79B1729CDFB1F00E7489F /* MPLaunchInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPLaunchInfo.h; sourceTree = "<group>"; };
53A79B1929CDFB1F00E7489F /* MPUserAttributeChange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPUserAttributeChange.h; sourceTree = "<group>"; };
53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPMessageBuilder.h; sourceTree = "<group>"; };
53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIUserDefaults.m; sourceTree = "<group>"; };
53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MPBracket.cpp; sourceTree = "<group>"; };
53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPUploadBuilder.h; sourceTree = "<group>"; };
53A79B2429CDFB1F00E7489F /* MPApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPApplication.h; sourceTree = "<group>"; };
53A79B2629CDFB1F00E7489F /* NSNumber+MPFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSNumber+MPFormatter.swift"; sourceTree = "<group>"; };
53A79B2729CDFB1F00E7489F /* MPUserAttributeChange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPUserAttributeChange.m; sourceTree = "<group>"; };
53A79B2929CDFB1F00E7489F /* MPLaunchInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPLaunchInfo.m; sourceTree = "<group>"; };
53A79B2A29CDFB1F00E7489F /* MParticleWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MParticleWebView.m; sourceTree = "<group>"; };
53A79B2B29CDFB1F00E7489F /* MPDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDevice.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1016,18 +1013,17 @@
53A79B1529CDFB1F00E7489F /* MPDevice.m */,
53A79B1629CDFB1F00E7489F /* MParticleWebView.h */,
53A79B1729CDFB1F00E7489F /* MPLaunchInfo.h */,
53A79B1929CDFB1F00E7489F /* MPUserAttributeChange.h */,
53A79B1A29CDFB1F00E7489F /* MPMessageBuilder.h */,
53A79B1D29CDFB1F00E7489F /* MPIUserDefaults.m */,
53A79B1E29CDFB1F00E7489F /* MPBracket.cpp */,
53A79B2329CDFB1F00E7489F /* MPUploadBuilder.h */,
53A79B2629CDFB1F00E7489F /* NSNumber+MPFormatter.swift */,
53A79B2729CDFB1F00E7489F /* MPUserAttributeChange.m */,
53A79B2929CDFB1F00E7489F /* MPLaunchInfo.m */,
53A79B2A29CDFB1F00E7489F /* MParticleWebView.m */,
53A79B2B29CDFB1F00E7489F /* MPDevice.h */,
53A79B2C29CDFB1F00E7489F /* MPBracket.h */,
53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */,
534C11B52D08F53D00466F71 /* MPUserAttributeChange.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1365,7 +1361,6 @@
53A79BC629CDFB2000E7489F /* MParticleReachability.h in Headers */,
53A79BF429CDFB2000E7489F /* MPCustomModule.h in Headers */,
53A79B8629CDFB2000E7489F /* MPPersistenceController.h in Headers */,
53A79BDE29CDFB2000E7489F /* MPUserAttributeChange.h in Headers */,
53A79B6E29CDFB2000E7489F /* MPIdentityDTO.h in Headers */,
53A79BDF29CDFB2000E7489F /* MPMessageBuilder.h in Headers */,
53A79B7429CDFB2000E7489F /* MPURLRequestBuilder.h in Headers */,
Expand Down Expand Up @@ -1458,7 +1453,6 @@
53A79D5129CE23F700E7489F /* MParticleReachability.h in Headers */,
53A79D5329CE23F700E7489F /* MPCustomModule.h in Headers */,
53A79D5529CE23F700E7489F /* MPPersistenceController.h in Headers */,
53A79D5729CE23F700E7489F /* MPUserAttributeChange.h in Headers */,
53A79D5829CE23F700E7489F /* MPIdentityDTO.h in Headers */,
53A79D5929CE23F700E7489F /* MPMessageBuilder.h in Headers */,
53A79D5A29CE23F700E7489F /* MPURLRequestBuilder.h in Headers */,
Expand Down Expand Up @@ -1777,6 +1771,7 @@
53A79BF829CDFB2000E7489F /* MPNotificationController.m in Sources */,
53A79C0829CDFB2100E7489F /* MPEvent.m in Sources */,
53A79B6729CDFB2000E7489F /* MPAliasResponse.m in Sources */,
534C11B72D08F53D00466F71 /* MPUserAttributeChange.swift in Sources */,
53A79C1229CDFB2100E7489F /* MPKitFilter.m in Sources */,
53A79B7829CDFB2000E7489F /* MPURLConnectionAssociate.m in Sources */,
53A79C0529CDFB2100E7489F /* MPTransactionAttributes.m in Sources */,
Expand All @@ -1791,7 +1786,6 @@
53A79C0E29CDFB2100E7489F /* MPKitContainer.mm in Sources */,
53A79BD729CDFB2000E7489F /* MPUploadBuilder.m in Sources */,
53A79C1129CDFB2100E7489F /* MPBaseProjection.m in Sources */,
53A79BEC29CDFB2000E7489F /* MPUserAttributeChange.m in Sources */,
53A79B7029CDFB2000E7489F /* MPIdentityApiManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1947,6 +1941,7 @@
53A79DA929CE23F700E7489F /* MPAppNotificationHandler.m in Sources */,
53A79DAA29CE23F700E7489F /* MPNotificationController.m in Sources */,
53A79DAB29CE23F700E7489F /* MPEvent.m in Sources */,
534C11B62D08F53D00466F71 /* MPUserAttributeChange.swift in Sources */,
53A79DAD29CE23F700E7489F /* MPAliasResponse.m in Sources */,
53A79DAE29CE23F700E7489F /* MPKitFilter.m in Sources */,
53A79DAF29CE23F700E7489F /* MPURLConnectionAssociate.m in Sources */,
Expand All @@ -1961,7 +1956,6 @@
53A79DB929CE23F700E7489F /* MPKitContainer.mm in Sources */,
53A79DBA29CE23F700E7489F /* MPUploadBuilder.m in Sources */,
53A79DBC29CE23F700E7489F /* MPBaseProjection.m in Sources */,
53A79DBE29CE23F700E7489F /* MPUserAttributeChange.m in Sources */,
53A79DBF29CE23F700E7489F /* MPIdentityApiManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
1 change: 1 addition & 0 deletions mParticle-Apple-SDK/Include/mParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
NS_ASSUME_NONNULL_BEGIN

@class MPSideloadedKit;
@class MPKitContainer;

/**
An SDK session.
Expand Down
1 change: 0 additions & 1 deletion mParticle-Apple-SDK/MPBackendController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#import "MPCommerceEvent.h"
#import "MPCommerceEvent+Dictionary.h"
#import "MPKitContainer.h"
#import "MPUserAttributeChange.h"
#import "MPURLRequestBuilder.h"
#import "MPListenerController.h"
#import "MParticleWebView.h"
Expand Down
1 change: 0 additions & 1 deletion mParticle-Apple-SDK/Utils/MPMessageBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#import "MPCommerceEvent+Dictionary.h"
#import "MPILogger.h"
#import "NSDictionary+MPCaseInsensitive.h"
#import "MPUserAttributeChange.h"
#import "MPPersistenceController.h"
#import "MPApplication.h"
#import "mParticle.h"
Expand Down
16 changes: 0 additions & 16 deletions mParticle-Apple-SDK/Utils/MPUserAttributeChange.h

This file was deleted.

62 changes: 0 additions & 62 deletions mParticle-Apple-SDK/Utils/MPUserAttributeChange.m

This file was deleted.

48 changes: 48 additions & 0 deletions mParticle-Apple-SDK/Utils/MPUserAttributeChange.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// MPUserAttributeChange.swift
// mParticle-Apple-SDK
//
// Created by Brandon Stalnaker on 12/9/24.
//

import Foundation

@objc public class MPUserAttributeChange : NSObject {

@objc public var key: String
@objc public var timestamp: Date?
@objc public var userAttributes: [String : Any]?
@objc public var value: Any?
@objc public var valueToLog: Any?
@objc public private(set) var changed: Bool
@objc public var deleted: Bool
@objc public var isArray: Bool

@objc public init?(userAttributes: [String : Any]? = nil, key: String, value: Any?) {
guard value == nil || value is [Any] || value is NSNull || value is String || value is NSNumber else {
return nil
}

if userAttributes == nil && value == nil {
return nil
}

self.key = key
self.value = value
self.deleted = false
self.valueToLog = value
self.userAttributes = userAttributes

let existingValue = userAttributes?[key]
self.isArray = (value is [Any] || existingValue is [Any])
self.changed = !equals(existingValue, value)
super.init()
}
}

fileprivate func equals(_ x : Any?, _ y : Any?) -> Bool {
guard let x = x as? AnyHashable, let y = y as? AnyHashable else {
return false
}
return x == y
}

0 comments on commit 488c9e3

Please sign in to comment.