-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'swift3' into feature/swift-device-extensions
- Loading branch information
Showing
13 changed files
with
410 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
language: objective-c | ||
before_install: | ||
- pod repo update --silent | ||
- gem install cocoapods --no-rdoc --no-ri --no-document --quiet | ||
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet | ||
- cd $TRAVIS_BUILD_DIR | ||
- pod install | ||
- pod install || pod install --repo-update | ||
script: rake test | ||
osx_image: xcode8 | ||
cache: cocoapods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
PiwikTracker.xcodeproj/xcshareddata/xcschemes/PiwikTracker.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Foundation | ||
|
||
/// The MemoryQueue is a **not thread safe** in memory Queue. | ||
struct MemoryQueue<E: Any>: Queue { | ||
typealias T = E | ||
private var items = [E]() | ||
|
||
var itemCount: Int { get { | ||
return items.count | ||
} | ||
} | ||
|
||
mutating func queue(item: T, completion: ()->()) { | ||
items.append(item) | ||
completion() | ||
} | ||
|
||
mutating func dequeue(withLimit limit: Int, completion: (_ items: [T])->()) { | ||
let amount = [limit,itemCount].min()! | ||
let dequeuedItems = Array(items[0..<amount]) | ||
items.removeSubrange(0..<amount) | ||
completion(dequeuedItems) | ||
} | ||
|
||
mutating func deleteAll() { | ||
items = [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import Foundation | ||
|
||
/// PiwikUserDefaults is a wrapper for the UserDefaults with properties | ||
/// mapping onto values stored in the UserDefaults. | ||
/// All getter and setter are sideeffect free and automatically syncronize | ||
/// after writing. | ||
internal struct PiwikUserDefaults { | ||
static let standard = PiwikUserDefaults() | ||
let userDefaults = UserDefaults.standard | ||
|
||
var totalNumberOfVisits: Int { | ||
get { | ||
return userDefaults.integer(forKey: PiwikUserDefaults.Key.totalNumberOfVisits) | ||
} | ||
set { | ||
userDefaults.set(newValue, forKey: PiwikUserDefaults.Key.totalNumberOfVisits) | ||
userDefaults.synchronize() | ||
} | ||
} | ||
|
||
var firstVisit: Date? { | ||
get { | ||
return userDefaults.object(forKey: PiwikUserDefaults.Key.firstVistsTimestamp) as? Date | ||
} | ||
set { | ||
userDefaults.set(newValue, forKey: PiwikUserDefaults.Key.firstVistsTimestamp) | ||
userDefaults.synchronize() | ||
} | ||
} | ||
|
||
var previousVisit: Date? { | ||
get { | ||
return userDefaults.object(forKey: PiwikUserDefaults.Key.previousVistsTimestamp) as? Date | ||
} | ||
set { | ||
userDefaults.set(newValue, forKey: PiwikUserDefaults.Key.previousVistsTimestamp) | ||
userDefaults.synchronize() | ||
} | ||
} | ||
|
||
var currentVisit: Date? { | ||
get { | ||
return userDefaults.object(forKey: PiwikUserDefaults.Key.currentVisitTimestamp) as? Date | ||
} | ||
set { | ||
userDefaults.set(newValue, forKey: PiwikUserDefaults.Key.currentVisitTimestamp) | ||
userDefaults.synchronize() | ||
} | ||
} | ||
|
||
var optOut: Bool { | ||
get { | ||
return userDefaults.bool(forKey: PiwikUserDefaults.Key.optOut) | ||
} | ||
set { | ||
userDefaults.set(newValue, forKey: PiwikUserDefaults.Key.optOut) | ||
userDefaults.synchronize() | ||
} | ||
} | ||
|
||
func clientId() -> String? { | ||
return userDefaults.string(forKey: PiwikUserDefaults.Key.visitorID) | ||
} | ||
|
||
func set(clientId: String) { | ||
userDefaults.setValue(clientId, forKey: PiwikUserDefaults.Key.visitorID) | ||
userDefaults.synchronize() | ||
} | ||
} | ||
|
||
extension PiwikUserDefaults { | ||
fileprivate struct Key { | ||
static let totalNumberOfVisits = "PiwikTotalNumberOfVistsKey" | ||
static let currentVisitTimestamp = "PiwikCurrentVisitTimestampKey" | ||
static let previousVistsTimestamp = "PiwikPreviousVistsTimestampKey" | ||
static let firstVistsTimestamp = "PiwikFirstVistsTimestampKey" | ||
static let visitorID = "PiwikVisitorIDKey" | ||
static let optOut = "PiwikOptOutKey" | ||
} | ||
} |
Oops, something went wrong.