Skip to content

Commit

Permalink
TD-222 updated to swift 3, moved from carthage cocoapods
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Alexa committed Dec 8, 2016
1 parent 2322514 commit b785b6a
Show file tree
Hide file tree
Showing 27 changed files with 302 additions and 147 deletions.
2 changes: 0 additions & 2 deletions Cartfile

This file was deleted.

3 changes: 0 additions & 3 deletions Cartfile.resolved

This file was deleted.

6 changes: 3 additions & 3 deletions TDCAppDependencies/Implementations/AnalyticEntities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct AnalyticEvent: CustomStringConvertible, Equatable {
public let label:String?

/// Internal variable used to highlight the mutability implications of the addInfo(_:value:) and setUserInfo(_:) methods.
private var _userInfo = [String:Any]()
fileprivate var _userInfo = [String:Any]()

/// Extra info specifc to this analytic event.
public var userInfo:[String:Any] {
Expand Down Expand Up @@ -56,7 +56,7 @@ public struct AnalyticEvent: CustomStringConvertible, Equatable {
- parameter key: The key to which the value will be assigned.
- parameter value: The value to be stored.
*/
public mutating func addInfo(key:String, value:Any) {
public mutating func addInfo(_ key:String, value:Any) {
_userInfo[key] = value
}

Expand All @@ -67,7 +67,7 @@ public struct AnalyticEvent: CustomStringConvertible, Equatable {
- parameter info: The info to be set.

*/
public mutating func setUserInfo(info:[String:Any]) {
public mutating func setUserInfo(_ info:[String:Any]) {
_userInfo = info
}

Expand Down
12 changes: 6 additions & 6 deletions TDCAppDependencies/Implementations/AppDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// Class that can be overriden that implements the properties required for the `_AppDependencies` protocol. Adopts `PreferencesInteractor` and all of its default ipmlementations.
public class AppDependencies: AppDependenciesSingleton, PreferencesInteractor {
open class AppDependencies: AppDependenciesSingleton, PreferencesInteractor {

/// The shared instance of an `AppDependenciesSingleton` or its subclass, whichever is referenced in execution first. This is achieved using `AppDependenciesSingleton`: a class that offers a singleton property that initialises as a subclass' type. This cannot be acheived in Swift, but can in Objective-C.
static func shared() -> Self {
Expand All @@ -26,26 +26,26 @@ public class AppDependencies: AppDependenciesSingleton, PreferencesInteractor {
}

/// The class that creates and returns `UIViewController`s for navigation.
public var viewLoader:ViewLoader?
open var viewLoader:ViewLoader?

/// Global variable for reporting crash related information.
public var crashReporter:CrashReporter? {
open var crashReporter:CrashReporter? {
didSet {
crashReporter?.setupCrashReporting()
}
}

/// Global variable for reporting analytics.
public var analyticsReporter:AnalyticsReporter? {
open var analyticsReporter:AnalyticsReporter? {
didSet {
analyticsReporter?.setupAnalytics()
}
}

/// Global variable for querying the user's preferences for crash reporting and analytics.
public var preferencesInteractor:PreferencesInteractor? {
open var preferencesInteractor:PreferencesInteractor? {
didSet {
preferencesInteractor?.setDefaultPreferences()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import Foundation
final public class TestAnalyticsReporter:AnalyticsReporter {

/// Internal variable for saving the events that are sent.
public private(set) var trackedEvents = [AnalyticEvent]()
public fileprivate(set) var trackedEvents = [AnalyticEvent]()

/// Empty method for protocol conformance.
public func enableAnalytics(enable: Bool) { }
public func enableAnalytics(_ enable: Bool) { }

/// Resets `tackedEvents` to an empty array. This can be called on `setup()` for any testing classes.
public func setupAnalytics() {
trackedEvents = [AnalyticEvent]()
}

/// Appends the new `event` to `trackedEvents. If `asNewSession` is not `nil`, `trackedEvents` is cleared before the event is append to the array. The event has the session added as an info element with key `session`.
public func sendAnalytic(event: AnalyticEvent, asNewSession session: AnalyticSession? = nil) {
public func sendAnalytic(_ event: AnalyticEvent, asNewSession session: AnalyticSession? = nil) {

// append the with new events.
var toRecord = event
Expand All @@ -35,4 +35,4 @@ final public class TestAnalyticsReporter:AnalyticsReporter {
}

public init() { }
}
}
10 changes: 5 additions & 5 deletions TDCAppDependencies/Implementations/TestCrashReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Foundation
final public class TestCrashReporter: CrashReporter {

/// Internal variable for saving the log messages.
public private(set) var messages = [String]()
public fileprivate(set) var messages = [String]()

/// Internal variable for saving non-fatal errors.
public private(set) var nonFatals = [NSError]()
public fileprivate(set) var nonFatals = [NSError]()

/// Resets `messages` and `nonFatals` to empty arrays. This can be called on `setup()` for any testing classes.
public func setupCrashReporting() {
Expand All @@ -22,7 +22,7 @@ final public class TestCrashReporter: CrashReporter {
}

/// Appends `message` to the `messages` array.
public func logToCrashReport(message: String) {
public func logToCrashReport(_ message: String) {
messages.append(message)
}

Expand All @@ -32,9 +32,9 @@ final public class TestCrashReporter: CrashReporter {
}

/// Appends `error` to the `nonFatals` array.
public func logNonFatalError(error: NSError) {
public func logNonFatalError(_ error: NSError) {
nonFatals.append(error)
}

public init() { }
}
}
10 changes: 5 additions & 5 deletions TDCAppDependencies/Protocols/AnalyticsReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol AnalyticSession {
public protocol AnalyticsReporter {

/// Should enable / disable further analytics from be sent.
func enableAnalytics(enable:Bool)
func enableAnalytics(_ enable:Bool)

/// Should be called before any other analytics methods to set the default properties, such as tracking ids.
func setupAnalytics()
Expand All @@ -32,22 +32,22 @@ public protocol AnalyticsReporter {
- parameter event: The event to send.
- parameter session: If this value is not nil, this should begin a new analytics session with the given configuration, closing a previously opened session. This should be called whenever anyhting in the session configuration changes, e.g. user logs out / in.
*/
func sendAnalytic(event:AnalyticEvent, asNewSession session:AnalyticSession?)
func sendAnalytic(_ event:AnalyticEvent, asNewSession session:AnalyticSession?)

/**

Should record the given analytic event. A default implementation is given which calls `sendAnalytic(_:asNewSession:)` without starting a new session.

- parameter event: The event to send.
*/
func sendAnalytic(event:AnalyticEvent)
func sendAnalytic(_ event:AnalyticEvent)
}

public extension AnalyticsReporter {

/// Calls `sendAnalytic(_:asNewSession:)` without starting a new session.
public func sendAnalytic(event:AnalyticEvent){
public func sendAnalytic(_ event:AnalyticEvent){
sendAnalytic(event, asNewSession: nil)
}

}
}
4 changes: 2 additions & 2 deletions TDCAppDependencies/Protocols/AppDependenciesProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public protocol _AppDependencies {

- parameter window: The window to add the root `UIViewController` to.
*/
func installRootViewControllerIntoWindow(window:UIWindow)
}
func installRootViewControllerIntoWindow(_ window:UIWindow)
}
6 changes: 3 additions & 3 deletions TDCAppDependencies/Protocols/CrashReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public protocol CrashReporter {
- parameter message: The message to be appended to the crash report.

*/
func logToCrashReport(message:String)
func logToCrashReport(_ message:String)

/**

Should report a non-fatal error to the crash reporting system.

- parameter error: The error to report.
*/
func logNonFatalError(error: NSError)
func logNonFatalError(_ error: NSError)

}
}
8 changes: 4 additions & 4 deletions TDCAppDependencies/Protocols/PreferencesInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public extension PreferencesInteractor {
*/
public func setDefaultPreferences() {
let prefs = [EnableCrashReportingPreferenceKey: true, EnableAnalyticsPreferenceKey: true]
NSUserDefaults.standardUserDefaults().registerDefaults(prefs)
UserDefaults.standard.register(defaults: prefs)
}

/// Queries settings bundle with `EnableAnalyticsPreferenceKey`.
public func canSendAnalytics() -> Bool {
return NSUserDefaults.standardUserDefaults().boolForKey(EnableAnalyticsPreferenceKey)
return UserDefaults.standard.bool(forKey: EnableAnalyticsPreferenceKey)
}

/// Queries settings bundle with `EnableCrashReportingPreferenceKey`.
public func canSendCrashReports() -> Bool {
return NSUserDefaults.standardUserDefaults().boolForKey(EnableCrashReportingPreferenceKey)
return UserDefaults.standard.bool(forKey: EnableCrashReportingPreferenceKey)
}

}
}
2 changes: 1 addition & 1 deletion TDCAppDependenciesTests/TDCAppDependenciesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TDCAppDependenciesTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
self.measure {
// Put the code you want to measure the time of here.
}
}
Expand Down
24 changes: 12 additions & 12 deletions TDCContentLoading/Model/Changeset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol ContentEquatable: Equatable {
- parameter other: The object to compare content against.
- returns: `true` if the content of `other` is the same as the content of `self`, `false` otherwise.
*/
@warn_unused_result

func contentMatches(other:Self) -> Bool
}

Expand Down Expand Up @@ -55,26 +55,26 @@ public struct Changeset<Element: ContentEquatable> {
self.oldItems = oldItems
self.newItems = newItems

deletions = oldItems.difference(newItems).map { item in
return Changeset.indexPathForIndex(oldItems.indexOf(item)!)
deletions = oldItems.difference(otherArray: newItems).map { item in
return Changeset.indexPathForIndex(index: oldItems.index(of: item)!)
}

modifications = oldItems.intersection(newItems)
modifications = oldItems.intersection(otherArray: newItems)
.filter({ item in
let newItem = newItems[newItems.indexOf(item)!]
return item.contentMatches(newItem)
let newItem = newItems[newItems.index(of: item)!]
return item.contentMatches(other: newItem)
})
.map({ item in
return Changeset.indexPathForIndex(oldItems.indexOf(item)!)
return Changeset.indexPathForIndex(index: oldItems.index(of: item)!)
})

insertions = newItems.difference(oldItems).map { item in
return NSIndexPath(forRow: newItems.indexOf(item)!, inSection: 0)
insertions = newItems.difference(otherArray: oldItems).map { item in
return NSIndexPath(row: newItems.index(of: item)!, section: 0)
}
}

private static func indexPathForIndex(index: Int) -> NSIndexPath {
return NSIndexPath(forRow: index, inSection: 0)
return NSIndexPath(row: index, section: 0)
}
}

Expand All @@ -99,12 +99,12 @@ extension Changeset: ChangesetLoadingModel {

/// `ListLoadingModel` conformance using `newItems` as an Array conforming to `ListLoadingModel`.
public func numberOfEntitiesInSection(section:Int) -> Int {
return newItems.numberOfEntitiesInSection(section)
return newItems.numberOfEntitiesInSection(section: section)
}

/// `ListLoadingModel` conformance using `newItems` as an Array conforming to `ListLoadingModel`.
public func entityForIndexPath(indexPath:NSIndexPath) -> ValueType? {
return newItems.entityForIndexPath(indexPath)
return newItems.entityForIndexPath(indexPath: indexPath)
}

/// - returns: The `newItems` as this represents the current content of this change.
Expand Down
2 changes: 1 addition & 1 deletion TDCContentLoading/Model/PagedOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension PagedOutput: ChangesetLoadingModel {

/// - returns: The number of objects in section 0. Paging sections is not yet implemented.
public func totalNumberOfEntities() -> Int {
return numberOfEntitiesInSection(0)
return numberOfEntitiesInSection(section: 0)
}

/// - returns: The specific object for a given `NSIndexPath` from `currentContent`, or `nil` if the `indexPath.row` is above the count of objects in `currentContent`, this occurs if there is more content available.
Expand Down
4 changes: 2 additions & 2 deletions TDCContentLoading/Protocols/ListLoadingContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public extension ListLoadingContainer {

/// - returns: `numberOfEntitiesInSection(_:)` for the contained `ListLoadingModel`.
public func numberOfEntitiesInSection(section: Int) -> Int {
return listLoadingModel.numberOfEntitiesInSection(section)
return listLoadingModel.numberOfEntitiesInSection(section: section)
}

/// - returns: `entityForIndexPath(_:)` as given by the contained `ListLoadingModel`.
public func entityForIndexPath(indexPath: NSIndexPath) -> ModelType.ValueType? {
return listLoadingModel.entityForIndexPath(indexPath)
return listLoadingModel.entityForIndexPath(indexPath: indexPath)
}
}
4 changes: 2 additions & 2 deletions TDCContentLoading/Protocols/ListLoadingModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import ReactiveCocoa
import ReactiveSwift
import Result

/**
Expand Down Expand Up @@ -49,4 +49,4 @@ public protocol ChangesetLoadingModel: ListLoadingModel {

/// Should return the current array of items that can populate the `Changeset`.
func currentItems() -> [ValueType]
}
}
Loading

0 comments on commit b785b6a

Please sign in to comment.