Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Swift 3.0 #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate
.DS_Store
*.swp
*.lock

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM


Carthage
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "Quick/Nimble" "v4.0.1"
github "Quick/Quick" "v0.9.2"
github "Quick/Nimble" "v5.0.0"
github "Quick/Quick" "v0.10.0"
21 changes: 20 additions & 1 deletion DataSourceable.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,18 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Zeker Waar";
TargetAttributes = {
B3E89A821BCCDFB900C0FB4C = {
CreatedOnToolsVersion = 7.0.1;
DevelopmentTeam = RS662E2L2G;
LastSwiftMigration = 0800;
};
B3E89A8C1BCCDFBA00C0FB4C = {
CreatedOnToolsVersion = 7.0.1;
DevelopmentTeam = RS662E2L2G;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -368,8 +372,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -416,8 +422,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -437,6 +445,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -448,7 +457,9 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = RS662E2L2G;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -460,14 +471,17 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
B3E89A991BCCDFBA00C0FB4C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = RS662E2L2G;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -478,12 +492,14 @@
PRODUCT_BUNDLE_IDENTIFIER = nl.zekerwaar.DataSourceable;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
B3E89A9B1BCCDFBA00C0FB4C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEVELOPMENT_TEAM = RS662E2L2G;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
Expand All @@ -492,12 +508,14 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = nl.zekerwaar.DataSourceableTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
B3E89A9C1BCCDFBA00C0FB4C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEVELOPMENT_TEAM = RS662E2L2G;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
Expand All @@ -506,6 +524,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = nl.zekerwaar.DataSourceableTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
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 = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions DataSourceable/CellProviding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

public protocol CellProviding {
func reuseIdentifier(forIndexPath indexPath: NSIndexPath) -> String
func reuseIdentifier(forIndexPath indexPath: IndexPath) -> String
}

public protocol TableViewCellProviding: CellProviding {
Expand All @@ -16,4 +16,4 @@ public protocol TableViewCellProviding: CellProviding {

public protocol CollectionViewCellProviding: CellProviding {
associatedtype CollectionViewCellType: Configurable
}
}
32 changes: 16 additions & 16 deletions DataSourceable/CollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@
//

public protocol CollectionViewDataSource {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView
func collectionView(collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: NSIndexPath) -> Bool
func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
func collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell
func numberOfSectionsInCollectionView(_ collectionView: UICollectionView) -> Int
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: IndexPath) -> UICollectionReusableView
func collectionView(_ collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: IndexPath) -> Bool
func collectionView(_ collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath)
}

public extension CollectionViewDataSource {
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
func numberOfSectionsInCollectionView(_ collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
return collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "", forIndexPath: indexPath)
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: IndexPath) -> UICollectionReusableView {
return collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "", for: indexPath)
}
func collectionView(collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: NSIndexPath) -> Bool {
func collectionView(_ collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: IndexPath) -> Bool {
return false
}
func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
func collectionView(_ collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: IndexPath, toIndexPath destinationIndexPath: IndexPath) {
}
}

public extension CollectionViewDataSource where Self: Sectionable {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return numberOfItems(inSection: section)
}

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
func numberOfSectionsInCollectionView(_ collectionView: UICollectionView) -> Int {
return numberOfSections
}
}

public extension CollectionViewDataSource where Self: Sectionable, Self: CollectionViewCellProviding, Self.CollectionViewCellType.ItemType == Self.Section.Data.Element {
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
func collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell {
let identifier = reuseIdentifier(forIndexPath: indexPath)
guard let item = item(atIndexPath: indexPath) else {
return UICollectionViewCell()
}

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath)
if let cell = cell as? CollectionViewCellType, view = collectionView as? CollectionViewCellType.ContainingViewType {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath)
if let cell = cell as? CollectionViewCellType, let view = collectionView as? CollectionViewCellType.ContainingViewType {
cell.configure(forItem: item, inView: view)
}
return cell
Expand Down
16 changes: 8 additions & 8 deletions DataSourceable/CollectionViewDataSourceProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
// Copyright © 2015 Zeker Waar. All rights reserved.
//

public class CollectionViewDataSourceProxy: NSObject, UICollectionViewDataSource {
public let dataSource: CollectionViewDataSource
open class CollectionViewDataSourceProxy: NSObject, UICollectionViewDataSource {
open let dataSource: CollectionViewDataSource

public init(dataSource: CollectionViewDataSource) {
self.dataSource = dataSource
}

public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataSource.collectionView(collectionView, numberOfItemsInSection: section)
}

public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return dataSource.collectionView(collectionView, cellForItemAtIndexPath: indexPath)
}

public func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
open func numberOfSections(in collectionView: UICollectionView) -> Int {
return dataSource.numberOfSectionsInCollectionView(collectionView)
}

public func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
open func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
return dataSource.collectionView(collectionView, viewForSupplementaryElementOfKind: kind, atIndexPath: indexPath)
}
public func collectionView(collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: NSIndexPath) -> Bool {
open func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
return dataSource.collectionView(collectionView, canMoveItemAtIndexPath: indexPath)
}
public func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
open func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
return dataSource.collectionView(collectionView, moveItemAtIndexPath: sourceIndexPath, toIndexPath: destinationIndexPath)
}
}
2 changes: 1 addition & 1 deletion DataSourceable/ElementsContaining.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public protocol ElementsContaining {
subscript(index: Int) -> Element? { get }
}

extension Indexable where Index == Int {
extension Collection where Index == Int {
var count: Int {
return endIndex
}
Expand Down
14 changes: 7 additions & 7 deletions DataSourceable/Loadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
//

public enum Result<Value, E> {
case Success(Value)
case Failure(E)
case success(Value)
case failure(E)
}

public protocol Loadable: class {
associatedtype Data : EmptyCheckable
var state: State<Data,ErrorType> { get set }
func loadData(completion: (Result<Data,ErrorType>) -> Void)
var state: State<Data,Error> { get set }
func loadData(_ completion: @escaping(Result<Data,Error>) -> Void)
}

public extension Loadable {
func reload(completion: () -> Void) {
func reload(_ completion: @escaping () -> Void) {
state = state.toLoading()
loadData { result in
switch result {
case .Success(let data):
case .success(let data):
self.state = self.state.toReady(data)
case .Failure(let error):
case .failure(let error):
self.state = self.state.toError(error)
}
completion()
Expand Down
8 changes: 4 additions & 4 deletions DataSourceable/Sectionable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public protocol Sectionable {
public protocol SectionCreating: Sectionable {
associatedtype Data
var data: Data? { get }
func createSections(data: Data) -> [Section]
func createSections(_ data: Data) -> [Section]
}

public extension Sectionable {
Expand All @@ -33,8 +33,8 @@ public extension Sectionable {
return section(atIndex: sectionIndex)?.numberOfItems ?? 0
}

func item(atIndexPath indexPath: NSIndexPath) -> Section.Data.Element? {
return section(atIndex: indexPath.section)?.item(atIndex: indexPath.row)
func item(atIndexPath indexPath: IndexPath) -> Section.Data.Element? {
return section(atIndex: (indexPath as NSIndexPath).section)?.item(atIndex: (indexPath as NSIndexPath).row)
}

func sectionHeader(atIndex index: Int) -> String? {
Expand Down Expand Up @@ -62,4 +62,4 @@ public extension Sectionable where Self : DataContaining, Self.Data == [Section]
var sections: [Section]? {
return data
}
}
}
Loading