Skip to content

Commit

Permalink
Prepare 4.6.0 release (#212)
Browse files Browse the repository at this point in the history
* Changes user-device to device model identifier (#75)

* installs new deviceModel into EnvironmentReporter and renames old deviceModel to deviceType

* use CwSysCtl for macos model

* Replaced entire flag store ff array instead of in place manipulation

* Updated CHANGELOG and bumped version number

* Added correct copy behavior to FlagStore delete and update

* Improved CHANGELOG entry for 4.0.1

* Changed version to 4.1.0, updated CHANGELOG

* Update 4.1.0 release date

* installs ios-eventsource 4.0.2

* installs CocoaPods 1.7.2

* clears swift 5 update warning

* updates circle config to use xcode 10.2.1

* advances version to 4.1.1

* installs Nimble 8.0.2

* updates SwiftLint to 0.33.0

* Update 4.1.1 release date

* Improved CHANGELOG 4.1.1 description

* Made CHANGELOG 4.1.1 more consistent

* 4.1.2 release, updated version numbers and CHANGELOG

* Made 4.1.2 CHANGELOG entry more descriptive

* Rebuilt Connection Status, added unit tests, fixed warnings

* Changed guard to equals in Dictionary extension, changed ConnectionInformation to struct

* Fixed threading issues and reference semantics

* Improved ConnectionInformation toString, fixed background behavior

* Added network connectivity check, changed TimeIntervals to Optionals

* Added Connection Status files to correct Target Membership, added conditional compilation of network connectivity check for WatchOS

* PR review changes

* More PR review changes

* Even more PR review changes

* Removed ConnectionInformationCaching, removed redundant variables

* Simplified synchronizing error behavior for connection status

* DRY up setupListeners

* Fixed string cases for LastConnectionFailureReason Codable

* Forgot to add polling last successful connection

* Store is now in Cache dir, removed listeners and 1 ldclient.shared, changed TimeInterval to Date, changed two inout's to var's

* Added ConnectionModeChangedObserver

* Fixed confusing docstring, removed unnecessary flag synchronizer

* Changed getValue and toString to description

* Changed description to computed property

* Removed connectionModeCheck

* Improved background connection status behavior

* Changed ConnectionInformation description to computed property

* Added new identify method, updated swiftlint rules

* Made Identify actually change the user, fixed unit tests

* Removed unnecessary _user assignment

* Move swiftlint disable to LDClient, move user assignment into identifyInternal

* Added private setOnline and go functions for identify

* Forgot to replace go in guard with goIdentify

* Copied user property unit tests for identify

* Added optimization to not call setOnline when there is no completion and wasOnline is false

* Testing identifyInternal change in IH

* requested PR changes

* Fixed convertCachedData call count, some PR feedback fixes

* Simplified unit tests, added comment about thread safety

* Changed lastSuccessfulConnection to lastKnownFlagValidity, added on stream close listener

* Fixed handler

* Remove unnecessary import

* Changed eventSource access level

* Reset lastKnownFlagValidity to nil when we make a successful stream connection

* Made comment about lastKnownFlagValidity having a value more clear

* Changed guard let to if let in DarklyService EventSource extension

* Updated README, CHANGELOG, and podspec for 4.2.0

* [4.2.1] - 2019-11-15 (#81)

* Added 4.2.1 changes including Dictionary fix and test and eventsource version bump

* Added Carthage build files

* Added attribution to CHANGELOG

* Evaluation Reasons (#82)

* Initial Evaluation Reasons prototype

* Changed evaluationReasons to reasons, fixed mangled question mark in url query parameters

* Added errorKinds

* Added reason to debug events

* Changed reason nil handling in events

* Removed unnecessary private functions, removed event nil coalesce

* Event change for reason nil

* Removed if in Event for reason nil, added guard let NSNull for dictionary in Events

* Added reason null to normal variation calls

* Testing alternate reason null set

* Change Event comparison code to add reason

* Removed reason from event dictionary matches

* Removed Event Equatable reason and changed Event Dictionary matches

* Explicitly set featureflag reason property to nil when not send feature event for variationDetail

* Fixed DeprecatedCacheModel unit tests, added v6 model tests, added variation detail unit tests, changed event reason nil check

* Added variationDetail to objective c, fixed cache converter unit tests, deprecated variationAndSource

* Added new files to correct target membership

* Simplify featureflag reason nil check

* Removed unnecessary comments, deprecated objc variationAndSource

* Improved doc strings, cut down on variation doc string repetition, added reason tests for Event and EventReporter, added EvaluationDetail generic

* Added ObjCEvaluationDetail to correct target membership

* Differentiated objc evaluation detail return type, change reason constant in unit tests

* Removed Optional value on fallback variation

* Added Event test for reason false but flag reason present, cleaned up objc doc strings, changed optional types in objc evaluation detail

* Experimentation 1.5 (#83)

* Added trackReasons and metricValue as well as doc and unit tests

* Added unit tests for reason false track reason true, added objc track without metricValue, changed and trackReason to or trackReason

* Added explicit event store reason test

* Fixed objc track comment

* Updated reason to includeReason for clarity

* Explicitly check both feature and debug events

* Prepare version 4.3.0

* Update ios-eventsource to 4.1.0 (#84)

* Updated ios-eventsource to 4.1.0, updated version strings

* Added sentence about iOS SDK compat to CHANGELOG

* pod repo update to get new eventsource version

* Fixed change listener not firing when only value changes (#85)

* Fixed change listener not firing when only value changes

* Fixed a unit test variable name typo

* Cast flag value to dictionary instead of string, improved unit test

* Remove debug printout, remove unnecessary parameter

* Updated CHANGELOG, README, and podspec for 4.3.2

* Adds startAwaitingFlags function (#86)

* Added newStart function, updated README, podspec, and CHANGELOG

* Changed newStart to startAwaitingFlags

* Added doc strings for startAwaitingFlags and deprecated start

* Added cocoapods lib lint flag to ignore depracted API usage in ObjCLDClient, added startAwaitingFlags to ObjC

* Fixed alow to allow, changed startAwaitFlags to startCompleteWhenFlagsReceived, added unit tests for startCompleteWhenFlagsReceived

* Updated deprecation message to startCompleteWhenFlagsReceived

* [ch61092] Add X-LaunchDarkly-Payload-ID to event request headers (#87)

* Added X-LaunchDarkly-Payload-ID header to event request headers, add string length check on LD payload ID header in header unit tests

* Added CHANGELOG Added entry for event request header

* Added UUID generation to DarklyService so it's regenerated on each request

* Change CHANGELOG entry for new header to match other SDKs

* Added single retry attempt to event post (#88)

* Added single retry attempt to event post

* Added payloadId to the correct point to maintain value between retries, retry on error

* reportSyncComplete on 2nd error, always log on event post error, add 1 second delay with log on event post retry

* Added 1 second delay to retry event post

* async'd event post to prevent blocking main thread on retry sleep

* Increased event test waitUntil timeout to 10 seconds

* Bumped patch version, added CHANGELOG for 4.4.1

* Changed 4.4.1 entry

* Further 4.4.1 entry revision

* Changed retry event post for loop to function call (#89)

* [ch65670] Fix Xcode 11.4 build and unit tests (#90)

* Fixed build errors, fixed some unit tests

* Added shell script to remove duplicate sourcery method mock

* sed now matches specific pattern instead of line numbers

* Add project config file containing run script step

* Bump CircleCI Xcode to 11.4

* Bump CircleCI Xcode to 11.4.0

* Changed iPhone simulator in CircleCI from XS to Xs

* Changed CircleCI xcodebuild from OS:latest to OS:12.4

* Testing NSURLRetryPolicy on CI

* Removed DeprecatedCache from automock

* Fix FlagStore to synchronize reads with writes.

* Add xcode compatibility information to readme (#93)

* Fix for concurrency bug exposed by restwrapper. (#94)

* General cleanup. (#92)

* [ch75316] Added maxCachedUsers to LDConfig and UserEnvironmentFlagCache (#96)

* Added maxCachedUsers to LDConfig and UserEnvironmentFlagCache

* Changed specific -1 to 0

* Added unlimited users tests

* Added CHANGELOG for 4.6

* Added maxCachedUsers to objc LDConfig (#97)

* Changed version to 4.6.0

Co-authored-by: Mark Pokorny <[email protected]>
Co-authored-by: Gavin Whelan <[email protected]>
Co-authored-by: Ben Woskow <[email protected]>
  • Loading branch information
4 people authored May 27, 2020
1 parent d5664df commit cc17e2e
Show file tree
Hide file tree
Showing 101 changed files with 1,649 additions and 3,162 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to the LaunchDarkly iOS SDK will be documented in this file.
### Multiple Environment clients
Version 4.0.0 does not support multiple environments. If you use version `2.14.0` or later and set `LDConfig`'s `secondaryMobileKeys` you will not be able to migrate to version `4.0.0`. Multiple Environments will be added in a future release to the Swift SDK.


## [4.6.0] - 2020-05-26
### Added
- Added `maxCachedUsers` option to `LDConfig`. You can now specify the number of users to be cached or use `-1` for unlimited cached users.

### Fixed
- `FlagStore` properly synchronizes reads and writes to prevent a potential race condition.

## [4.5.0] - 2020-03-26
### Changed
- Updated SDK code to build, run, and test on Xcode 11.4.
Expand Down
4 changes: 2 additions & 2 deletions LaunchDarkly.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |ld|

ld.name = "LaunchDarkly"
ld.version = "4.5.0"
ld.version = "4.6.0"
ld.summary = "iOS SDK for LaunchDarkly"

ld.description = <<-DESC
Expand All @@ -25,7 +25,7 @@ Pod::Spec.new do |ld|
ld.tvos.deployment_target = "9.0"
ld.osx.deployment_target = "10.10"

ld.source = { :git => "https://github.com/launchdarkly/ios-client-sdk.git", :tag => '4.5.0'}
ld.source = { :git => "https://github.com/launchdarkly/ios-client-sdk.git", :tag => '4.6.0'}

ld.source_files = "LaunchDarkly/LaunchDarkly/**/*.{h,m,swift}"

Expand Down
10 changes: 0 additions & 10 deletions LaunchDarkly.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
8311885E2113AE2900D77CB5 /* HTTPURLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B8C2461FE4071F0082B8A9 /* HTTPURLResponse.swift */; };
8311885F2113AE2D00D77CB5 /* HTTPURLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830BF932202D188E006DF9B1 /* HTTPURLRequest.swift */; };
831188602113AE3400D77CB5 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83EF67891F97CFEC00403126 /* Dictionary.swift */; };
831188612113AE3700D77CB5 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E2E2081F9FF9E1007514E9 /* Optional.swift */; };
831188622113AE3A00D77CB5 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEF51FA24A7E00E428B6 /* Data.swift */; };
831188632113AE3F00D77CB5 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEF91FA24AFB00E428B6 /* Array.swift */; };
831188642113AE4200D77CB5 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEFB1FA24B2700E428B6 /* JSONSerialization.swift */; };
Expand Down Expand Up @@ -97,7 +96,6 @@
831EF35C20655E730001C643 /* HTTPURLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B8C2461FE4071F0082B8A9 /* HTTPURLResponse.swift */; };
831EF35D20655E730001C643 /* HTTPURLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830BF932202D188E006DF9B1 /* HTTPURLRequest.swift */; };
831EF35E20655E730001C643 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83EF67891F97CFEC00403126 /* Dictionary.swift */; };
831EF35F20655E730001C643 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E2E2081F9FF9E1007514E9 /* Optional.swift */; };
831EF36020655E730001C643 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEF51FA24A7E00E428B6 /* Data.swift */; };
831EF36120655E730001C643 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEF91FA24AFB00E428B6 /* Array.swift */; };
831EF36220655E730001C643 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEFB1FA24B2700E428B6 /* JSONSerialization.swift */; };
Expand Down Expand Up @@ -259,7 +257,6 @@
83D9EC8E2062DEAB004D7FA6 /* HTTPURLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B8C2461FE4071F0082B8A9 /* HTTPURLResponse.swift */; };
83D9EC8F2062DEAB004D7FA6 /* HTTPURLRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830BF932202D188E006DF9B1 /* HTTPURLRequest.swift */; };
83D9EC902062DEAB004D7FA6 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83EF67891F97CFEC00403126 /* Dictionary.swift */; };
83D9EC912062DEAB004D7FA6 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E2E2081F9FF9E1007514E9 /* Optional.swift */; };
83D9EC922062DEAB004D7FA6 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEF51FA24A7E00E428B6 /* Data.swift */; };
83D9EC932062DEAB004D7FA6 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEF91FA24AFB00E428B6 /* Array.swift */; };
83D9EC942062DEAB004D7FA6 /* JSONSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEFB1FA24B2700E428B6 /* JSONSerialization.swift */; };
Expand All @@ -278,7 +275,6 @@
83DDBEFE1FA24F9600E428B6 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEFD1FA24F9600E428B6 /* Date.swift */; };
83DDBF001FA2589900E428B6 /* FlagStoreSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83DDBEFF1FA2589900E428B6 /* FlagStoreSpec.swift */; };
83E2E2061F9E7AC7007514E9 /* LDUserSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E2E2051F9E7AC7007514E9 /* LDUserSpec.swift */; };
83E2E2091F9FF9E1007514E9 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E2E2081F9FF9E1007514E9 /* Optional.swift */; };
83EBCBA320D9A1F3003A7142 /* FlagValueCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83EBCBA220D9A1F3003A7142 /* FlagValueCounter.swift */; };
83EBCBA420D9A1F3003A7142 /* FlagValueCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83EBCBA220D9A1F3003A7142 /* FlagValueCounter.swift */; };
83EBCBA520D9A1F3003A7142 /* FlagValueCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83EBCBA220D9A1F3003A7142 /* FlagValueCounter.swift */; };
Expand Down Expand Up @@ -453,7 +449,6 @@
83DDBEFD1FA24F9600E428B6 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
83DDBEFF1FA2589900E428B6 /* FlagStoreSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlagStoreSpec.swift; sourceTree = "<group>"; };
83E2E2051F9E7AC7007514E9 /* LDUserSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LDUserSpec.swift; sourceTree = "<group>"; };
83E2E2081F9FF9E1007514E9 /* Optional.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = "<group>"; };
83EBCBA220D9A1F3003A7142 /* FlagValueCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlagValueCounter.swift; sourceTree = "<group>"; };
83EBCBA920D9A451003A7142 /* FlagValueCounterSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlagValueCounterSpec.swift; sourceTree = "<group>"; };
83EBCBAB20D9C6A6003A7142 /* FlagCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlagCounter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -818,7 +813,6 @@
isa = PBXGroup;
children = (
83EF67891F97CFEC00403126 /* Dictionary.swift */,
83E2E2081F9FF9E1007514E9 /* Optional.swift */,
83DDBEF51FA24A7E00E428B6 /* Data.swift */,
83DDBEF91FA24AFB00E428B6 /* Array.swift */,
83DDBEFB1FA24B2700E428B6 /* JSONSerialization.swift */,
Expand Down Expand Up @@ -1447,7 +1441,6 @@
C443A40523145FBF00145710 /* ConnectionInformation.swift in Sources */,
8354AC732243166900CDE602 /* UserEnvironmentFlagCache.swift in Sources */,
8311885B2113AE1D00D77CB5 /* Throttler.swift in Sources */,
831188612113AE3700D77CB5 /* Optional.swift in Sources */,
8311884E2113ADE500D77CB5 /* Event.swift in Sources */,
832D68A5224A38FC005F052A /* CacheConverter.swift in Sources */,
831188482113ADD100D77CB5 /* LDFlagValueConvertible.swift in Sources */,
Expand Down Expand Up @@ -1515,7 +1508,6 @@
8370DF6E225E40B800F84810 /* DeprecatedCache.swift in Sources */,
C43C37E7238DF22C003C1624 /* EvaluationDetail.swift in Sources */,
835F43D320D0309A0070DE51 /* EventTrackingContext.swift in Sources */,
831EF35F20655E730001C643 /* Optional.swift in Sources */,
831EF36020655E730001C643 /* Data.swift in Sources */,
83EBCBB520DABE1B003A7142 /* FlagRequestTracker.swift in Sources */,
831EF36120655E730001C643 /* Array.swift in Sources */,
Expand Down Expand Up @@ -1548,7 +1540,6 @@
837EF3742059C237009D628A /* Log.swift in Sources */,
835F43D120D0309A0070DE51 /* EventTrackingContext.swift in Sources */,
83FEF8DD1F266742001CF12C /* FlagSynchronizer.swift in Sources */,
83E2E2091F9FF9E1007514E9 /* Optional.swift in Sources */,
835E1D471F68B3EC00184DB4 /* ObjcLDFlagValue.swift in Sources */,
83883DD5220B68A000EEAB95 /* ErrorObserver.swift in Sources */,
830BF933202D188E006DF9B1 /* HTTPURLRequest.swift in Sources */,
Expand Down Expand Up @@ -1712,7 +1703,6 @@
C43C37EA238DF238003C1624 /* DeprecatedCacheModelV6.swift in Sources */,
83D9EC902062DEAB004D7FA6 /* Dictionary.swift in Sources */,
831425B2206B030100F2EF36 /* EnvironmentReporter.swift in Sources */,
83D9EC912062DEAB004D7FA6 /* Optional.swift in Sources */,
83D9EC922062DEAB004D7FA6 /* Data.swift in Sources */,
8347BB0D21F147E100E56BCD /* LDTimer.swift in Sources */,
8354AC712243166900CDE602 /* UserEnvironmentFlagCache.swift in Sources */,
Expand Down
10 changes: 10 additions & 0 deletions LaunchDarkly/GeneratedCode/mocks.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ final class EventReportingMock: EventReporting {
// MARK: - FeatureFlagCachingMock
final class FeatureFlagCachingMock: FeatureFlagCaching {

// MARK: maxCachedUsers
var maxCachedUsersSetCount = 0
var setMaxCachedUsersCallback: (() -> Void)?
var maxCachedUsers: Int = 5 {
didSet {
maxCachedUsersSetCount += 1
setMaxCachedUsersCallback?()
}
}

// MARK: retrieveFeatureFlags
var retrieveFeatureFlagsCallCount = 0
var retrieveFeatureFlagsCallback: (() -> Void)?
Expand Down
29 changes: 14 additions & 15 deletions LaunchDarkly/LaunchDarkly/Extensions/AnyComparer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,67 @@
// Any.swift
// LaunchDarkly
//
// Created by Mark Pokorny on 11/9/17. +JMJ
// Copyright © 2017 Catamorphic Co. All rights reserved.
//

import Foundation

struct AnyComparer {
private init() { }

//If editing this method to add classes here, update AnySpec with tests that verify the comparison for that class
//swiftlint:disable:next cyclomatic_complexity
public static func isEqual(_ value: Any, to other: Any) -> Bool {
switch (value, other) {
case (let value as Bool, let other as Bool):
case let (value, other) as (Bool, Bool):
if value != other {
return false
}
case (let value as Int, let other as Int):
case let (value, other) as (Int, Int):
if value != other {
return false
}
case (let value as Int, let other as Double):
case let (value, other) as (Int, Double):
if Double(value) != other {
return false
}
case (let value as Double, let other as Int):
case let (value, other) as (Double, Int):
if value != Double(other) {
return false
}
case (let value as Int64, let other as Int64):
case let (value, other) as (Int64, Int64):
if value != other {
return false
}
case (let value as Int64, let other as Double):
case let (value, other) as (Int64, Double):
if Double(value) != other {
return false
}
case (let value as Double, let other as Int64):
case let (value, other) as (Double, Int64):
if value != Double(other) {
return false
}
case (let value as Double, let other as Double):
case let (value, other) as (Double, Double):
if value != other {
return false
}
case (let value as String, let other as String):
case let (value, other) as (String, String):
if value != other {
return false
}
case (let value as [Any], let other as [Any]):
case let (value, other) as ([Any], [Any]):
if !value.isEqual(to: other) {
return false
}
case (let value as [String: Any], let other as [String: Any]):
case let (value, other) as ([String: Any], [String: Any]):
if !value.isEqual(to: other) {
return false
}
case (let value as Date, let other as Date):
case let (value, other) as (Date, Date):
if value != other {
return false
}
case (let value as FeatureFlag, let other as FeatureFlag):
case let (value, other) as (FeatureFlag, FeatureFlag):
if value != other {
return false
}
Expand Down
1 change: 0 additions & 1 deletion LaunchDarkly/LaunchDarkly/Extensions/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Array.swift
// LaunchDarkly
//
// Created by Mark Pokorny on 10/26/17. +JMJ
// Copyright © 2017 Catamorphic Co. All rights reserved.
//

Expand Down
5 changes: 2 additions & 3 deletions LaunchDarkly/LaunchDarkly/Extensions/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
// Data.swift
// LaunchDarkly
//
// Created by Mark Pokorny on 10/26/17. +JMJ
// Copyright © 2017 Catamorphic Co. All rights reserved.
//

import Foundation

extension Data {
var base64UrlEncodedString: String {
return base64EncodedString().replacingOccurrences(of: "+", with: "-").replacingOccurrences(of: "/", with: "_")
base64EncodedString().replacingOccurrences(of: "+", with: "-").replacingOccurrences(of: "/", with: "_")
}

var jsonDictionary: [String: Any]? {
return try? JSONSerialization.jsonDictionary(with: self, options: [.allowFragments])
try? JSONSerialization.jsonDictionary(with: self, options: [.allowFragments])
}
}
7 changes: 3 additions & 4 deletions LaunchDarkly/LaunchDarkly/Extensions/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import Foundation

extension Date {
var millisSince1970: Int64 {
return Int64(floor(self.timeIntervalSince1970 * 1000))
Int64(floor(self.timeIntervalSince1970 * 1_000))
}

init?(millisSince1970: Int64?) {
guard let millisSince1970 = millisSince1970, millisSince1970 >= 0
else {
return nil
}
self = Date(timeIntervalSince1970: Double(millisSince1970) / 1000)
self = Date(timeIntervalSince1970: Double(millisSince1970) / 1_000)
}

func isWithin(_ timeInterval: TimeInterval, of otherDate: Date?) -> Bool {
Expand All @@ -30,7 +30,6 @@ extension Date {
}

func isEarlierThan(_ otherDate: Date) -> Bool {
let timeDifference = self.timeIntervalSince(otherDate)
return timeDifference < 0.0
self.timeIntervalSince(otherDate) < 0.0
}
}
3 changes: 1 addition & 2 deletions LaunchDarkly/LaunchDarkly/Extensions/DateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// DateFormatter.swift
// LaunchDarkly
//
// Created by Mark Pokorny on 6/15/18. +JMJ
// Copyright © 2018 Catamorphic Co. All rights reserved.
//

Expand All @@ -14,7 +13,7 @@ extension DateFormatter {
httpUrlHeaderFormatter.locale = Locale(identifier: "en_US_POSIX")
httpUrlHeaderFormatter.timeZone = TimeZone(abbreviation: "GMT")
httpUrlHeaderFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz" //Mon, 07 May 2018 19:46:29 GMT

return httpUrlHeaderFormatter
}
}
54 changes: 12 additions & 42 deletions LaunchDarkly/LaunchDarkly/Extensions/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Dictionary.swift
// LaunchDarkly
//
// Created by Mark Pokorny on 10/18/17. +JMJ
// Copyright © 2017 Catamorphic Co. All rights reserved.
//

Expand All @@ -11,29 +10,21 @@ import Foundation
extension Dictionary where Key == String {
var jsonString: String? {
guard let encodedDictionary = jsonData
else {
return nil
}
else { return nil }
return String(data: encodedDictionary, encoding: .utf8)
}

var jsonData: Data? {
guard JSONSerialization.isValidJSONObject(self)
else {
return nil
}
else { return nil }
return try? JSONSerialization.data(withJSONObject: self, options: [])
}

func isEqual(to other: [String: Any]) -> Bool {
guard self.count == other.count
else {
return false
}
else { return false }
guard self.keys.sorted() == other.keys.sorted()
else {
return false
}
else { return false }
for key in self.keys {
if !AnyComparer.isEqual(self[key], to: other[key]) {
return false
Expand All @@ -47,30 +38,25 @@ extension Dictionary where Key == String {
let rightKeys: Set<String> = Set(other.keys)
let differingKeys = leftKeys.symmetricDifference(rightKeys)
let matchingKeys = leftKeys.intersection(rightKeys)
let matchingKeysWithDifferentValues = matchingKeys.filter { (key) -> Bool in
let matchingKeysWithDifferentValues = matchingKeys.filter { key -> Bool in
!AnyComparer.isEqual(self[key], to: other[key])
}
return differingKeys.union(matchingKeysWithDifferentValues).sorted()
}

var base64UrlEncodedString: String? {
return jsonData?.base64UrlEncodedString
jsonData?.base64UrlEncodedString
}
}

extension Dictionary where Key == String, Value == Any {
var withNullValuesRemoved: [String: Any] {
var filteredDictionary = self.filter { (_, value) in
!(value is NSNull)
}
filteredDictionary = filteredDictionary.mapValues { (value) in
guard let dictionary = value as? [String: Any]
else {
return value
self.filter { !($1 is NSNull) }.mapValues { value in
if let dictionary = value as? [String: Any] {
return dictionary.withNullValuesRemoved
}
return dictionary.withNullValuesRemoved
return value
}
return filteredDictionary
}
}

Expand All @@ -93,22 +79,6 @@ extension Optional where Wrapped == [String: Any] {
}

public static func != (lhs: [String: Any]?, rhs: [String: Any]?) -> Bool {
return !(lhs == rhs)
}
}

extension Dictionary {
func compactMapValues<T>(_ transform: (Dictionary.Value) throws -> T?) rethrows -> Dictionary<Dictionary.Key, T> {
var dictionary = [Dictionary.Key: T]()
try self.mapValues(transform).compactMap { (keyValuePair) -> (Dictionary.Key, T)? in
guard let value = keyValuePair.value
else {
return nil
}
return (keyValuePair.key, value)
}.forEach { (pair: (key: Dictionary.Key, value: T)) in
dictionary[pair.key] = pair.value
}
return dictionary
!(lhs == rhs)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// JSONSerialization.swift
// LaunchDarkly
//
// Created by Mark Pokorny on 10/26/17. +JMJ
// Copyright © 2017 Catamorphic Co. All rights reserved.
//

Expand Down
Loading

0 comments on commit cc17e2e

Please sign in to comment.