Skip to content

Commit

Permalink
Added debug print and weak self in operation closures. (#69)
Browse files Browse the repository at this point in the history
* Added debug print and `weak self` in operation closures.
  • Loading branch information
jey-starratt authored Sep 23, 2021
1 parent 318ca85 commit 42a8cac
Show file tree
Hide file tree
Showing 65 changed files with 753 additions and 678 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.4] - 2021-09-23
### Changed
- Added debug print.

### Fixed
- `weak self` in operation closures.

## [2.0.3] - 2021-02-16
### Fixed
- API error response parsing
Expand Down
2 changes: 1 addition & 1 deletion MailchimpSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'MailchimpSDK'
s.version = '2.0.3'
s.version = '2.0.4'
s.summary = 'Mailchimp SDK for iOS'

s.description = <<-DESC
Expand Down
4 changes: 3 additions & 1 deletion PanionApp/PanionApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1100;
LastUpgradeCheck = 1100;
LastUpgradeCheck = 1250;
ORGANIZATIONNAME = "The Rocket Science Group LLC";
TargetAttributes = {
F235666422B41EE60064C041 = {
Expand Down Expand Up @@ -312,6 +312,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -372,6 +373,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
16 changes: 11 additions & 5 deletions Sources/MailchimpSDK/MailchimpSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
8D3BCA6C2566E66200F9C268 /* EventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D3BCA662566E66200F9C268 /* EventTests.swift */; };
8D3BCA6D2566E66200F9C268 /* MergeFieldTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D3BCA682566E66200F9C268 /* MergeFieldTests.swift */; };
8D3BCA6E2566E66200F9C268 /* ContactTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D3BCA692566E66200F9C268 /* ContactTests.swift */; };
8DF0738326F8EB6900F0544C /* Debug.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DF0738226F8EB6900F0544C /* Debug.swift */; };
B95896A122774C0C00F7509B /* MailchimpSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B958969722774C0C00F7509B /* MailchimpSDK.framework */; };
B95896A822774C0C00F7509B /* MailchimpSDK.h in Headers */ = {isa = PBXBuildFile; fileRef = B958969A22774C0C00F7509B /* MailchimpSDK.h */; settings = {ATTRIBUTES = (Public, ); }; };
B95896B82277689F00F7509B /* URLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B95896B72277689F00F7509B /* URLRequest.swift */; };
Expand Down Expand Up @@ -47,6 +48,7 @@
8D3BCA682566E66200F9C268 /* MergeFieldTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MergeFieldTests.swift; sourceTree = "<group>"; };
8D3BCA692566E66200F9C268 /* ContactTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactTests.swift; sourceTree = "<group>"; };
8D3BCA6A2566E66200F9C268 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8DF0738226F8EB6900F0544C /* Debug.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Debug.swift; sourceTree = "<group>"; };
B958969722774C0C00F7509B /* MailchimpSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MailchimpSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B958969A22774C0C00F7509B /* MailchimpSDK.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MailchimpSDK.h; sourceTree = "<group>"; };
B958969B22774C0C00F7509B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -183,6 +185,7 @@
children = (
B95896B72277689F00F7509B /* URLRequest.swift */,
B95896C5227B73CC00F7509B /* Result.swift */,
8DF0738226F8EB6900F0544C /* Debug.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -273,7 +276,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1100;
LastUpgradeCheck = 1110;
LastUpgradeCheck = 1250;
ORGANIZATIONNAME = "The Rocket Science Group LLC";
TargetAttributes = {
B958969622774C0C00F7509B = {
Expand Down Expand Up @@ -342,6 +345,7 @@
B95896BD227768AB00F7509B /* APIRequest.swift in Sources */,
B95896B82277689F00F7509B /* URLRequest.swift in Sources */,
F239C3FD229F2DDF00FB85C3 /* CountryCode.swift in Sources */,
8DF0738326F8EB6900F0544C /* Debug.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -394,6 +398,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -460,6 +465,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -512,7 +518,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.0.3;
MARKETING_VERSION = 2.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.theRocketScienceGroup.MailchimpSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -541,7 +547,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.0.3;
MARKETING_VERSION = 2.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.theRocketScienceGroup.MailchimpSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand All @@ -561,7 +567,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.0.3;
MARKETING_VERSION = 2.0.4;
PRODUCT_BUNDLE_IDENTIFIER = "com.theRocketScienceGroup.Mailchimp-SDKTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -580,7 +586,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.0.3;
MARKETING_VERSION = 2.0.4;
PRODUCT_BUNDLE_IDENTIFIER = "com.theRocketScienceGroup.Mailchimp-SDKTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1110"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1220"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
29 changes: 29 additions & 0 deletions Sources/MailchimpSDK/MailchimpSDK/Core/Extensions/Debug.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
//
// Debug.swift
// MailchimpSDK
//
// Created by Jennifer Starratt on 9/20/21.
// Copyright 2021 The Rocket Science Group LLC
//
// Licensed under the Mailchimp Mobile SDK License Agreement (the "License");
// you may not use this file except in compliance with the License. Unless
// required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
// OR CONDITIONS OF ANY KIND, either or express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

/// A debug version of print. `print()` will only be called if debug mode is enabled.
///
/// - Parameters:
/// - items: Zero or more items to print.
/// - separator: A string to print between each item. The default is a single space (" ").
/// - terminator: The string to print after all items have been printed. The default is a newline ("\n").
func debugPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") {
if Mailchimp.debugMode {
print(items, separator: separator, terminator: terminator)
}
}
10 changes: 3 additions & 7 deletions Sources/MailchimpSDK/MailchimpSDK/SDK/Mailchimp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public class Mailchimp: NSObject {
Mailchimp.autoTagContacts = autoTagContacts
Mailchimp.debugMode = debugMode

if debugMode {
print("Mailchimp SDK Initialized. Version: \(version)")
}
debugPrint("Mailchimp SDK Initialized. Version: \(version)")
}

/// Creates a new Contact and permanently sets the status. If the Contact already exists, contact
Expand All @@ -76,10 +74,8 @@ public class Mailchimp: NSObject {
let combinedTags = autoTags() + (contactInfo.tags ?? [])
contactInfo.tags = combinedTags

if debugMode {
for tag in autoTags() {
print("Adding auto-tag \"\(tag.name)\" to create contact request.")
}
for tag in autoTags() {
debugPrint("Adding auto-tag \"\(tag.name)\" to create contact request.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,21 @@ public class ContactOperation: Operation {
} else {
state = .executing

request = ContactRequest(contact: contact) { requestResult in
request = ContactRequest(contact: contact) { [weak self] requestResult in
guard let self = self else { return }

self.result?(requestResult)

if Mailchimp.debugMode {
switch requestResult {
case .success:
print("Contact request succeeded.")
debugPrint("Contact request succeeded.")
case .failure(let error):
print("Contact request failed with error: \(error.localizedDescription)")
debugPrint("Contact request failed with error: \(error.localizedDescription)")
if case .apiError(let response) = error {
print("API Error status: \(response.status)")
print("API Error detail: \(response.detail)")
print("API Error type: \(response.type)")
debugPrint("API Error status: \(response.status)")
debugPrint("API Error detail: \(response.detail ?? "Unknown")")
debugPrint("API Error type: \(response.type ?? "Unknown")")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,21 @@ public class EventOperation: Operation {
} else {
state = .executing

request = EventRequest(event: event) { requestResult in
request = EventRequest(event: event) { [weak self] requestResult in
guard let self = self else { return }

self.result?(requestResult)

if Mailchimp.debugMode {
switch requestResult {
case .success:
print("Event request succeeded.")
debugPrint("Event request succeeded.")
case .failure(let error):
print("Event request failed with error: \(error.localizedDescription)")
debugPrint("Event request failed with error: \(error.localizedDescription)")
if case .apiError(let response) = error {
print("API Error status: \(response.status)")
print("API Error detail: \(response.detail)")
print("API Error type: \(response.type)")
debugPrint("API Error status: \(response.status)")
debugPrint("API Error detail: \(response.detail ?? "Unknown")")
debugPrint("API Error type: \(response.type ?? "Unknown")")
}
}
}
Expand Down
Loading

0 comments on commit 42a8cac

Please sign in to comment.