Skip to content

Commit

Permalink
Migrated to Swift 4 (#199)
Browse files Browse the repository at this point in the history
* Migrated to Swift 4

* Fixed travis

* Fixed tests

* Fixed travis again

* Fixed travis again-again
  • Loading branch information
jay18001 authored Nov 22, 2017
1 parent daf9dd4 commit 74a320c
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 180 deletions.
26 changes: 11 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,25 @@ env:
- WORKSPACE=BrickKit.xcworkspace
- IOS_FRAMEWORK_SCHEME="BrickKit"
- TVOS_FRAMEWORK_SCHEME="BrickKit-tvOS"
- IOS_SDK=iphonesimulator10.3
- IOS_BETA_SDK=iphonesimulator11.0
- TVOS_SDK=appletvsimulator10.2
- IOS_SDK=iphonesimulator11.1
- TVOS_SDK=appletvsimulator11.1
- IOS_EXAMPLE_SCHEME="BrickApp-iOS"
- TVOS_EXAMPLE_SCHEME="BrickApp-tvOS"

matrix:
include:
- osx_image: xcode8.3
- osx_image: xcode9.1
env:
- DESTINATION="OS=9.0,name=iPhone 5" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" EXAMPLE_SCHEME="$IOS_EXAMPLE_SCHEME"
- osx_image: xcode8.3
- DESTINATION="OS=10.0,name=iPhone SE" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" EXAMPLE_SCHEME="$IOS_EXAMPLE_SCHEME"
- osx_image: xcode9.1
env:
- DESTINATION="OS=10.0,name=iPhone 7 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" EXAMPLE_SCHEME="$IOS_EXAMPLE_SCHEME"
- osx_image: xcode9
- DESTINATION="OS=11.1,name=iPhone 7 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" EXAMPLE_SCHEME="$IOS_EXAMPLE_SCHEME"
- osx_image: xcode9.1
env:
- DESTINATION="OS=11.0,name=iPhone 7 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_BETA_SDK" EXAMPLE_SCHEME="$IOS_EXAMPLE_SCHEME"

- osx_image: xcode8.3
env:
- DESTINATION="OS=9.0,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" EXAMPLE_SCHEME="$TVOS_EXAMPLE_SCHEME"
- osx_image: xcode8.3
- DESTINATION="OS=10.0,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" EXAMPLE_SCHEME="$TVOS_EXAMPLE_SCHEME"
- osx_image: xcode9.1
env:
- DESTINATION="OS=10.0,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" EXAMPLE_SCHEME="$TVOS_EXAMPLE_SCHEME"
- DESTINATION="OS=11.1,name=Apple TV" SCHEME="$TVOS_FRAMEWORK_SCHEME" SDK="$TVOS_SDK" EXAMPLE_SCHEME="$TVOS_EXAMPLE_SCHEME"
script:
- set -o pipefail
- xcodebuild -version
Expand All @@ -42,3 +37,4 @@ script:

after_success:
- bash <(curl -s https://codecov.io/bash) -J 'BrickKit' -X xcodeplist

16 changes: 8 additions & 8 deletions BrickKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@
PRODUCT_NAME = "$(PROJECT_NAME)";
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1465,7 +1465,7 @@
PRODUCT_NAME = "$(PROJECT_NAME)";
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1481,7 +1481,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.wafair.BrickKit-tvOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
Expand All @@ -1496,7 +1496,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.wafair.BrickKit-tvOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Release;
Expand Down Expand Up @@ -1633,7 +1633,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wayfair.BrickKit;
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -1654,7 +1654,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wayfair.BrickKit;
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -1668,7 +1668,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.wayfair.BrickKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -1682,7 +1682,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.wayfair.BrickKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
4 changes: 4 additions & 0 deletions Example/BrickKit-Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.wafair.BrickKit-Example";
PRODUCT_NAME = BrickApp;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -1270,6 +1271,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.wafair.BrickKit-Example";
PRODUCT_NAME = BrickApp;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -1285,6 +1287,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.wafair.BrickApp-tvOS";
PRODUCT_NAME = BrickApp;
SDKROOT = appletvos;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1302,6 +1305,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.wafair.BrickApp-tvOS";
PRODUCT_NAME = BrickApp;
SDKROOT = appletvos;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ class InsertBrickViewController: BrickApp.BaseBrickController, HasTitle {
}
}

func setAppearIndex(sender: UISegmentedControl) {
@objc func setAppearIndex(sender: UISegmentedControl) {
self.selectedAppearSegmentIndex = sender.selectedSegmentIndex
}

func setInsertIndex(sender: UISegmentedControl) {
@objc func setInsertIndex(sender: UISegmentedControl) {
self.selectedInsertSegmentIndex = sender.selectedSegmentIndex
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,7 @@ class ReorderableBrickViewController: BrickViewController, HasTitle {
], inset: 20, edgeInsets: UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10))

self.setSection(section)

self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(test))
}

func test() {
for section in 0..<self.brickCollectionView.section.bricks.count {
print("Section: \(section)")
for i in 0..<repeatCount {
let indexPaths = self.brickCollectionView.indexPathsForBricksWithIdentifier(label1.identifier, index: i)
print("Label 1 Index \(i): \(indexPaths[section].item)")
}
for i in 0..<repeatCount {
let indexPaths = self.brickCollectionView.indexPathsForBricksWithIdentifier(label2.identifier, index: i)
print("Label 2 Index \(i): \(indexPaths[section].item)")
}
print("\n\n")
}
}

}

extension ReorderableBrickViewController: BrickSectionOrderDataSource {
Expand Down
12 changes: 6 additions & 6 deletions Example/Source/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Theme {
// Navigation
UINavigationBar.appearance().barTintColor = .brickBackground
UINavigationBar.appearance().titleTextAttributes = [
NSForegroundColorAttributeName: Theme.textColorForNavigationTitle,
NSFontAttributeName: Theme.fontForNavigationTitle
.foregroundColor: Theme.textColorForNavigationTitle,
.font: Theme.fontForNavigationTitle
]

// EdgeInsets
Expand All @@ -52,8 +52,8 @@ class Theme {
navigationBar.barTintColor = .brickBackground
navigationBar.tintColor = .brickPurple1
navigationBar.titleTextAttributes = [
NSForegroundColorAttributeName: Theme.textColorForNavigationTitle,
NSFontAttributeName: Theme.fontForNavigationTitle
.foregroundColor: Theme.textColorForNavigationTitle,
.font: Theme.fontForNavigationTitle
]
#endif
}
Expand All @@ -63,8 +63,8 @@ class Theme {
navigationBar.barTintColor = .brickPurple3
navigationBar.tintColor = .brickGray1
navigationBar.titleTextAttributes = [
NSForegroundColorAttributeName: UIColor.brickGray1,
NSFontAttributeName: Theme.fontForNavigationTitle
.foregroundColor: UIColor.brickGray1,
.font: Theme.fontForNavigationTitle
]
#endif
}
Expand Down
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ With BrickKit, you can create complex and responsive layouts in a simple way. It
```swift

let section = BrickSection(bricks: [
LabelBrick(width: .Ratio(ratio: 1), text: "BRICK 1"),
LabelBrick(width: .Ratio(ratio: 1), text: "MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK"),
LabelBrick(width: .Ratio(ratio: 1/2), text: "1/2 BRICK"),
LabelBrick(width: .Ratio(ratio: 1/2), text: "1/2 BRICK"),
LabelBrick(width: .Ratio(ratio: 1/3), text: "1/3 BRICK"),
LabelBrick(width: .Ratio(ratio: 1/3), text: "1/3 BRICK"),
LabelBrick(width: .Ratio(ratio: 1/3), text: "1/3 BRICK"),
LabelBrick(width: .ratio(ratio: 1), text: "BRICK 1"),
LabelBrick(width: .ratio(ratio: 1), text: "MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK MULTI-LINE BRICK"),
LabelBrick(width: .ratio(ratio: 1/2), text: "1/2 BRICK"),
LabelBrick(width: .ratio(ratio: 1/2), text: "1/2 BRICK"),
LabelBrick(width: .ratio(ratio: 1/3), text: "1/3 BRICK"),
LabelBrick(width: .ratio(ratio: 1/3), text: "1/3 BRICK"),
LabelBrick(width: .ratio(ratio: 1/3), text: "1/3 BRICK"),
], inset: 10, edgeInsets: UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20))

self.setSection(section)
Expand All @@ -47,24 +47,24 @@ self.setSection(section)
```swift

// Calculate height using auto-layout
LabelBrick(height: .Auto(estimate: .Fixed(size: 50)), text: "BRICK"),
LabelBrick(height: .auto(estimate: .fixed(size: 50)), text: "BRICK"),

// Fixed Height
LabelBrick(height: .Fixed(size: 50), text: "BRICK"),
LabelBrick(height: .fixed(size: 50), text: "BRICK"),

// Calculate height based on ratio of the width
LabelBrick(height: .Ratio(ratio: 1), text: "BRICK"),
LabelBrick(height: .ratio(ratio: 1), text: "BRICK"),

// Complex Rule based on size classes and/or orientation
let height: BrickDimension =
.HorizontalSizeClass(
regular: .Orientation(
landscape: .Fixed(size: 200),
portrait: .Fixed(size: 100)
.horizontalSizeClass(
regular: .orientation(
landscape: .fixed(size: 200),
portrait: .fixed(size: 100)
),
compact: .Orientation(
landscape: .Fixed(size: 100),
portrait: .Fixed(size: 50)
compact: .orientation(
landscape: .fixed(size: 100),
portrait: .fixed(size: 50)
)
)

Expand All @@ -79,28 +79,28 @@ let height: BrickDimension =
```swift

let section = BrickSection(bricks: [
LabelBrick(width: .Ratio(ratio: 0.5), text: "BRICK"),
BrickSection(width: .Ratio(ratio: 0.5), bricks: [
LabelBrick(width: .ratio(ratio: 0.5), text: "BRICK"),
BrickSection(width: .ratio(ratio: 0.5), bricks: [
LabelBrick(text: "BRICK\nBRICK"),
LabelBrick(text: "BRICK"),
LabelBrick(text: "BRICK"),
], inset: 10),
BrickSection(bricks: [
BrickSection(width: .Ratio(ratio: 1/3), bricks: [
BrickSection(width: .ratio(ratio: 1/3), bricks: [
LabelBrick(text: "BRICK"),
LabelBrick(text: "BRICK"),
], inset: 5),
BrickSection(width: .Ratio(ratio: 2/3), backgroundColor: .brickGray3, bricks: [
BrickSection(width: .ratio(ratio: 2/3), backgroundColor: .brickGray3, bricks: [
LabelBrick(text: "BRICK"),
LabelBrick(text: "BRICK"),
LabelBrick(text: "BRICK"),
], inset: 15),
], inset: 5, edgeInsets: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)),
BrickSection(width: .Ratio(ratio: 0.5), bricks: [
BrickSection(width: .ratio(ratio: 0.5), bricks: [
LabelBrick(text: "BRICK"),
LabelBrick(text: "BRICK"),
], inset: 10),
LabelBrick(width: .Ratio(ratio: 0.5), text: "BRICK"),
LabelBrick(width: .ratio(ratio: 0.5), text: "BRICK"),
LabelBrick(text: "BRICK"),
], inset: 10, edgeInsets: UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20))

Expand All @@ -120,8 +120,8 @@ registerBrickClass(NiblessBrick.self)

let section = BrickSection(bricks: [
NiblessBrick(text: "BRICK", image: UIImage(named: "logo_splash")!),
NiblessBrick(width: .Ratio(ratio: 1/2), text: "BRICK", image: UIImage(named: "logo_inapp")!),
NiblessBrick(width: .Ratio(ratio: 1/2), text: "BRICK", image: UIImage(named: "logo_inapp")!)
NiblessBrick(width: .ratio(ratio: 1/2), text: "BRICK", image: UIImage(named: "logo_inapp")!),
NiblessBrick(width: .ratio(ratio: 1/2), text: "BRICK", image: UIImage(named: "logo_inapp")!)
], inset: 10)
setSection(section)

Expand All @@ -139,27 +139,27 @@ self.registerBrickClass(CollectionBrick.self)
self.registerBrickClass(LabelBrick.self)

let section1 = BrickSection(bricks: [
ImageBrick(width: .Ratio(ratio: 1/4), height: .Ratio(ratio: 1), dataSource: self),
ImageBrick(width: .ratio(ratio: 1/4), height: .ratio(ratio: 1), dataSource: self),
] , inset: 10, edgeInsets: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5))
section1.repeatCountDataSource = self

let section2 = BrickSection(bricks: [
ImageBrick(width: .Ratio(ratio: 1/2), height: .Ratio(ratio: 1), dataSource: self),
ImageBrick(width: .ratio(ratio: 1/2), height: .ratio(ratio: 1), dataSource: self),
], inset: 10, edgeInsets: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5))
section2.repeatCountDataSource = self

let section3 = BrickSection(bricks: [
ImageBrick(width: .Fixed(size: 100), height: .Ratio(ratio: 1), dataSource: self),
ImageBrick(width: .fixed(size: 100), height: .ratio(ratio: 1), dataSource: self),
], inset: 10, edgeInsets: UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5))
section3.repeatCountDataSource = self

let section = BrickSection(bricks: [
LabelBrick(text: "1/4 Ratio"),
CollectionBrick(scrollDirection: .Horizontal, dataSource: CollectionBrickCellModel(section: section1), brickTypes: [ImageBrick.self]),
CollectionBrick(scrollDirection: .horizontal, dataSource: CollectionBrickCellModel(section: section1), brickTypes: [ImageBrick.self]),
LabelBrick(text: "1/2 Ratio"),
CollectionBrick(scrollDirection: .Horizontal, dataSource: CollectionBrickCellModel(section: section2), brickTypes: [ImageBrick.self]),
CollectionBrick(scrollDirection: .horizontal, dataSource: CollectionBrickCellModel(section: section2), brickTypes: [ImageBrick.self]),
LabelBrick(text: "100px Fixed"),
CollectionBrick(scrollDirection: .Horizontal, dataSource: CollectionBrickCellModel(section: section3), brickTypes: [ImageBrick.self]),
CollectionBrick(scrollDirection: .horizontal, dataSource: CollectionBrickCellModel(section: section3), brickTypes: [ImageBrick.self]),
])
setSection(section)

Expand All @@ -180,11 +180,11 @@ let imageURL = NSURL(string:"https://secure.img2.wfrcdn.com/lf/8/hash/2664/10628

let section = BrickSection("RootSection", bricks: [
LabelBrick(text: "Below is an image brick with fixed height"),
ImageBrick(height: .Fixed(size: 50)dataSource: ImageURLBrickModel(url: imageURL, contentMode: .ScaleAspectFit)),
ImageBrick(height: .fixed(size: 50)dataSource: ImageURLBrickModel(url: imageURL, contentMode: .ScaleAspectFit)),
LabelBrick(text: "Below is an image brick loaded dynamically"),
ImageBrick(height: .Auto(estimate: .Fixed(size: 50)), dataSource: ImageURLBrickModel(url: imageURL, contentMode: .ScaleAspectFit)),
ImageBrick(height: .auto(estimate: .fixed(size: 50)), dataSource: ImageURLBrickModel(url: imageURL, contentMode: .ScaleAspectFit)),
LabelBrick(text: "Below is an image brick with fixed height"),
ImageBrick(height: .Fixed(size: 50), dataSource: ImageURLBrickModel(url: imageURL, contentMode: .ScaleAspectFill)),
ImageBrick(height: .fixed(size: 50), dataSource: ImageURLBrickModel(url: imageURL, contentMode: .scaleAspectFill)),
], inset: 10)

self.setSection(section)
Expand All @@ -210,9 +210,9 @@ func stickyLayoutBehavior(stickyLayoutBehavior: StickyLayoutBehavior, shouldStic

```swift

layout.scrollDirection = .Horizontal
layout.scrollDirection = .horizontal

let snapToBehavior = SnapToPointLayoutBehavior(scrollDirection: .Horizontal(.Center))
let snapToBehavior = SnapToPointLayoutBehavior(scrollDirection: .horizontal(.Center))
self.brickCollectionView.layout.behaviors.insert(snapToBehavior)
self.brickCollectionView.layout.behaviors.insert(CoverFlowLayoutBehavior(minimumScaleFactor: 0.75))

Expand Down
2 changes: 1 addition & 1 deletion Source/Bricks/Collection/CollectionBrick.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ extension CollectionBrickCell: BrickLayoutDelegate {
return
}

self.resizeDelegate?.performResize(cell: self, completion: { [weak self] _ in
self.resizeDelegate?.performResize(cell: self, completion: { [weak self] in
self?.brickCollectionView.layoutSubviews()
})
}
Expand Down
Loading

0 comments on commit 74a320c

Please sign in to comment.