Updating test cases

This commit is contained in:
Yannick Loriot 2018-12-10 15:13:52 +01:00
parent cfc6bb4d46
commit d15740a175
5 changed files with 44 additions and 34 deletions

View File

@ -695,6 +695,7 @@
};
CEA4D1311D95642900B12DAB = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 1010;
ProvisioningStyle = Manual;
};
CECBCD801B2B6C5E0047E731 = {
@ -1244,7 +1245,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yannickloriot.iOSTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
@ -1262,7 +1264,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yannickloriot.iOSTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Release;
};
@ -1287,7 +1290,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
@ -1312,7 +1314,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
@ -1444,7 +1445,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
@ -1494,7 +1495,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
@ -1511,7 +1512,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = DynamicColorExample;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Debug;
@ -1527,7 +1527,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.yannickloriot.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = DynamicColorExample;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Release;

View File

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@ -25,43 +24,45 @@
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="ZnU-ha-wtg">
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="nPS-bG-bQS">
<size key="itemSize" width="110" height="110"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="5" minimumInteritemSpacing="5" id="nPS-bG-bQS">
<size key="itemSize" width="100" height="100"/>
<size key="headerReferenceSize" width="50" height="40"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="5" minY="5" maxX="5" maxY="5"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="ColorCell" id="kI2-tn-Nfh" customClass="ColorCellView" customModule="DynamicColorExample" customModuleProvider="target">
<rect key="frame" x="5" y="45" width="110" height="110"/>
<rect key="frame" x="5" y="45" width="100" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="110" height="110"/>
<rect key="frame" x="0.0" y="0.0" width="100" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FnG-8L-jxj">
<rect key="frame" x="8" y="81" width="94" height="21"/>
<rect key="frame" x="8" y="72" width="84" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="uzt-Ro-x22"/>
<constraint firstAttribute="height" constant="20" id="uzt-Ro-x22"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Rc6-DF-Q4M">
<rect key="frame" x="23" y="8" width="64" height="65"/>
<rect key="frame" x="22" y="8" width="56" height="56"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" secondItem="Rc6-DF-Q4M" secondAttribute="height" multiplier="1:1" id="ZcT-oE-VHk"/>
</constraints>
</view>
</subviews>
</view>
<constraints>
<constraint firstItem="Rc6-DF-Q4M" firstAttribute="leading" secondItem="kI2-tn-Nfh" secondAttribute="leadingMargin" constant="15" id="O7l-A2-caD"/>
<constraint firstItem="Rc6-DF-Q4M" firstAttribute="top" secondItem="kI2-tn-Nfh" secondAttribute="topMargin" id="OqP-Sg-BTn"/>
<constraint firstItem="FnG-8L-jxj" firstAttribute="top" secondItem="Rc6-DF-Q4M" secondAttribute="bottom" constant="8" symbolic="YES" id="Y6C-tF-hqQ"/>
<constraint firstItem="Rc6-DF-Q4M" firstAttribute="top" secondItem="kI2-tn-Nfh" secondAttribute="top" constant="8" id="0p0-1V-VCq"/>
<constraint firstItem="FnG-8L-jxj" firstAttribute="top" secondItem="Rc6-DF-Q4M" secondAttribute="bottom" constant="8" id="Kwu-rj-2Y4"/>
<constraint firstAttribute="bottom" secondItem="FnG-8L-jxj" secondAttribute="bottom" constant="8" id="XaF-0w-54c"/>
<constraint firstItem="FnG-8L-jxj" firstAttribute="trailing" secondItem="kI2-tn-Nfh" secondAttribute="trailingMargin" id="eg1-F0-T3w"/>
<constraint firstItem="FnG-8L-jxj" firstAttribute="centerX" secondItem="Rc6-DF-Q4M" secondAttribute="centerX" id="m75-EN-AAL"/>
<constraint firstItem="FnG-8L-jxj" firstAttribute="leading" secondItem="kI2-tn-Nfh" secondAttribute="leadingMargin" id="p4b-Jb-ONe"/>
<constraint firstItem="FnG-8L-jxj" firstAttribute="bottom" secondItem="kI2-tn-Nfh" secondAttribute="bottomMargin" id="rCl-M0-QKp"/>
</constraints>
<connections>
<outlet property="colorView" destination="Rc6-DF-Q4M" id="Z5h-os-ycb"/>
@ -103,6 +104,7 @@
</collectionReusableView>
<connections>
<outlet property="dataSource" destination="BYZ-38-t0r" id="gz3-w5-0nS"/>
<outlet property="delegate" destination="BYZ-38-t0r" id="cUN-0M-Afp"/>
</connections>
</collectionView>
<navigationBar contentMode="scaleToFill" translucent="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dM4-Qp-1H6">

View File

@ -12,9 +12,7 @@ final class ColorCellView: UICollectionViewCell {
@IBOutlet weak var colorView: UIView?
@IBOutlet weak var titleLabel: UILabel!
override func layoutSubviews() {
super.layoutSubviews()
func layoutColorView() {
if let cv = colorView {
cv.layer.cornerRadius = cv.bounds.width / 2
}

View File

@ -8,7 +8,7 @@
import UIKit
class ViewController: UIViewController, UICollectionViewDataSource {
class ViewController: UIViewController {
private let colorCellIdentifier = "ColorCell"
@IBOutlet weak var colorCollectionView: UICollectionView!
@ -41,9 +41,9 @@ class ViewController: UIViewController, UICollectionViewDataSource {
func collection(inSection section: Int) -> [(String, UIColor)] {
return section == 0 ? colors : gradients
}
}
// MARK: - UICollectionView DataSource Methods
extension ViewController: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
@ -53,13 +53,9 @@ class ViewController: UIViewController, UICollectionViewDataSource {
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// swiftlint:disable force_cast
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: colorCellIdentifier, for: indexPath) as! ColorCellView
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: colorCellIdentifier, for: indexPath)
let (title, color) = collection(inSection: indexPath.section)[indexPath.row]
cell.titleLabel?.text = title
cell.colorView?.backgroundColor = color
self.collectionView(collectionView, willDisplay: cell, forItemAt: indexPath)
return cell
}
@ -72,3 +68,17 @@ class ViewController: UIViewController, UICollectionViewDataSource {
return supplementaryView
}
}
extension ViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
guard let cell = cell as? ColorCellView else { return }
let (title, color) = collection(inSection: indexPath.section)[indexPath.row]
cell.titleLabel?.text = title
cell.colorView?.backgroundColor = color
cell.layoutColorView()
}
}

View File

@ -49,6 +49,7 @@ class DynamicColorTests: XCTestCase {
XCTAssert(redAlphaStandard.isEqual(redAlphaHex), "Color should be equals")
let overflowedColor = DynamicColor(hexString: "#FFFFFFFF")
XCTAssert(overflowedColor.isEqual(toHex: 0xFFFFFF), "Color should be equals")
}
func testToHexString() {