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

Add weak link SwiftUI framework #63

Merged
merged 10 commits into from
Oct 30, 2019
Merged
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
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ jobs:
strategy:
fail-fast: false
matrix:
xcode_version: ["10.2", "11.1"]
xcode_version:
- 11.1
destination:
- platform=iOS Simulator,name=iPhone 11 Pro,OS=13.1
- platform=iOS Simulator,name=iPhone SE,OS=10.0
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode_version }}.app
steps:
Expand All @@ -18,6 +22,6 @@ jobs:
run: |
swift --version
xcodebuild -version
- name: Test iOS on Xcode ${{ matrix.xcode_version }}
- name: Test iOS on Xcode ${{ matrix.xcode_version }} simulator ${{ matrix.destination }}
run: |
set -o pipefail && xcodebuild build-for-testing test-without-building -workspace Carbon.xcworkspace -scheme Carbon -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8' ENABLE_TESTABILITY=YES | xcpretty -c
set -o pipefail && xcodebuild build-for-testing test-without-building -workspace Carbon.xcworkspace -scheme Carbon -configuration Release -sdk iphonesimulator -destination '${{ matrix.destination }}' ENABLE_TESTABILITY=YES | xcpretty -c
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0
5.1
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type_body_length:
warning: 400

function_body_length:
warning: 50
warning: 60

cyclomatic_complexity:
warning: 12
Expand Down
5 changes: 3 additions & 2 deletions Carbon.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'Carbon'
spec.version = '1.0.0-rc.5'
spec.version = '1.0.0-rc.6'
spec.author = { 'ra1028' => 'r.fe51028.r@gmail.com' }
spec.homepage = 'https://github.com/ra1028/Carbon'
spec.documentation_url = 'https://ra1028.github.io/Carbon'
Expand All @@ -9,8 +9,9 @@ Pod::Spec.new do |spec|
spec.source_files = 'Sources/**/*.swift'
spec.license = { :type => 'Apache 2.0', :file => 'LICENSE' }
spec.requires_arc = true
spec.swift_versions = ['5.0', '5.1']
spec.swift_versions = ['5.1']
spec.ios.deployment_target = '10.0'
spec.dependency 'DifferenceKit/Core', "~> 1.1"
spec.ios.frameworks = 'UIKit'
spec.ios.weak_frameworks = 'SwiftUI'
end
4 changes: 2 additions & 2 deletions Carbon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
OTHER_LDFLAGS = "";
OTHER_LDFLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = com.ryo.Carbon;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -798,7 +798,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
OTHER_LDFLAGS = "";
OTHER_LDFLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = com.ryo.Carbon;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
22 changes: 9 additions & 13 deletions Carbon.xcodeproj/xcshareddata/xcschemes/Carbon.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6B65947921E252E300291AAF"
BuildableName = "Carbon.framework"
BlueprintName = "Carbon"
ReferencedContainer = "container:Carbon.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -39,17 +48,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6B65947921E252E300291AAF"
BuildableName = "Carbon.framework"
BlueprintName = "Carbon"
ReferencedContainer = "container:Carbon.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -70,8 +68,6 @@
ReferencedContainer = "container:Carbon.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ in UITableView and UICollectionView.</br>
<a href="https://github.com/Carthage/Carthage"><img alt="Carthage" src="https://img.shields.io/badge/carthage-compatible-yellow.svg"/></a>
</br>
<a href="https://github.com/ra1028/Carbon/actions"><img alt="CI Status" src="https://github.com/ra1028/Carbon/workflows/GitHub%20Actions/badge.svg"/></a>
<a href="https://developer.apple.com/swift"><img alt="Swift5" src="https://img.shields.io/badge/language-Swift5-orange.svg"/></a>
<a href="https://developer.apple.com/swift"><img alt="Swift 5.1" src="https://img.shields.io/badge/language-Swift 5.1-orange.svg"/></a>
<a href="https://developer.apple.com/"><img alt="Platform" src="https://img.shields.io/badge/platform-iOS-green.svg"/></a>
<a href="https://github.com/ra1028/Carbon/blob/master/LICENSE"><img alt="Lincense" src="https://img.shields.io/badge/License-Apache%202.0-black.svg"/></a>
</p>
Expand Down Expand Up @@ -271,7 +271,7 @@ renderer.render {

<H3 align="center">
<a href="https://ra1028.github.io/Carbon">[See More Usage]</a>
<a href="https://github.com/ra1028/Carbon/tree/declarative/Examples/Example-iOS">[See Example App]</a>
<a href="https://github.com/ra1028/Carbon/tree/master/Examples/Example-iOS">[See Example App]</a>
</H3>

---
Expand Down Expand Up @@ -522,7 +522,7 @@ Default is `true`.

### Without FunctionBuilder Syntax

If you are using Swift 5, you cannot use the function builder that you have queried so far, but Carbon can also build a UI with declarative syntax without function builder as following.
Carbon can also build a UI with declarative syntax without function builder as following.

- **ViewNode**

Expand Down Expand Up @@ -567,10 +567,8 @@ renderer.render(

## Requirements

- Swift 5.0+
- Xcode 10.2+

Note: function builder syntax requires Swift5.1+ and Xcode 11.0+
- Swift 5.1+
- Xcode 11.0+

---

Expand All @@ -589,7 +587,7 @@ github "ra1028/Carbon"
```

### [Swift Package Manager](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app)
Select Xcode menu File > Swift Packages > Add Package Dependency and enter repository URL with GUI.
Select Xcode menu `File > Swift Packages > Add Package Dependency...` and enter repository URL with GUI.
```
Repository: https://github.com/ra1028/Carbon
```
Expand Down
16 changes: 0 additions & 16 deletions Sources/ComponentWrapper/ComponentWrapping.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import UIKit

#if swift(>=5.1)

/// Represents a wrapper of component that forwards all actions to wrapped component.
/// You can easily conform arbitrary type to `Component` protocol by wrapping component instance.
@dynamicMemberLookup
Expand All @@ -21,20 +19,6 @@ public extension ComponentWrapping {
}
}

#else

/// Represents a wrapper of component that forwards all actions to wrapped component.
/// You can easily conform arbitrary type to `Component` protocol by wrapping component instance.
public protocol ComponentWrapping: Component {
/// The type of wrapped component.
associatedtype Wrapped: Component

/// The wrapped component instance.
var wrapped: Wrapped { get }
}

#endif

public extension ComponentWrapping {
/// A string used to identify a element that is reusable. Default is the type name of `self`.
@inlinable
Expand Down
4 changes: 0 additions & 4 deletions Sources/FunctionBuilder/CellsBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if swift(>=5.1)

// swiftlint:disable line_length
// swiftlint:disable function_parameter_count

Expand Down Expand Up @@ -174,5 +172,3 @@ internal extension CellsBuilder {
cellNodes = cellNodes0 + cellNodes1 + cellNodes2 + c9.buildCells()
}
}

#endif
4 changes: 0 additions & 4 deletions Sources/FunctionBuilder/Group.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if swift(>=5.1)

/// An affordance for grouping component or section.
///
/// Example for simple grouping of cells.
Expand Down Expand Up @@ -82,5 +80,3 @@ extension Group: SectionsBuildable where Element == Section {
elements
}
}

#endif
4 changes: 0 additions & 4 deletions Sources/FunctionBuilder/SectionsBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if swift(>=5.1)

// swiftlint:disable line_length
// swiftlint:disable function_parameter_count

Expand Down Expand Up @@ -173,5 +171,3 @@ internal extension SectionsBuilder {
sections = sections0 + sections1 + sections2 + s9.buildSections()
}
}

#endif
6 changes: 0 additions & 6 deletions Sources/Renderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ open class Renderer<Updater: Carbon.Updater> {
open func render(_ data: Section?...) {
render(data.compactMap { $0 })
}
}

#if swift(>=5.1)

extension Renderer {
/// Render given variadic number of sections with function builder syntax, immediately.
///
/// - Parameters:
Expand All @@ -117,6 +113,4 @@ extension Renderer {
}
}

#endif

private struct UniqueIdentifier: Hashable {}
20 changes: 7 additions & 13 deletions Sources/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,14 @@ public struct Section {
footer: footer
)
}
}

#if swift(>=5.1)

public extension Section {
/// Create a section wrapping given id and cells with function builder syntax.
///
/// - Parameters:
/// - id: An identifier to be wrapped.
/// - cells: A closure that constructs cells.
@inlinable
init<I: Hashable, C: CellsBuildable>(id: I, @CellsBuilder cells: () -> C) {
public init<I: Hashable, C: CellsBuildable>(id: I, @CellsBuilder cells: () -> C) {
self.init(
id: id,
cells: cells().buildCells()
Expand All @@ -117,7 +113,7 @@ public extension Section {
/// - footer: A footer component.
/// - cells: A closure that constructs cells.
@inlinable
init<I: Hashable, H: Component, F: Component, C: CellsBuildable>(id: I, header: H?, footer: F?, @CellsBuilder cells: () -> C) {
public init<I: Hashable, H: Component, F: Component, C: CellsBuildable>(id: I, header: H?, footer: F?, @CellsBuilder cells: () -> C) {
self.init(
id: id,
header: header.map(ViewNode.init),
Expand All @@ -133,7 +129,7 @@ public extension Section {
/// - header: A header component.
/// - footer: A footer component.
@inlinable
init<I: Hashable, H: Component, F: Component>(id: I, header: H?, footer: F?) {
public init<I: Hashable, H: Component, F: Component>(id: I, header: H?, footer: F?) {
self.init(
id: id,
header: header.map(ViewNode.init),
Expand All @@ -148,7 +144,7 @@ public extension Section {
/// - header: A header component.
/// - cells: A closure that constructs cells.
@inlinable
init<I: Hashable, H: Component>(id: I, header: H?, @CellsBuilder cells: () -> CellsBuildable) {
public init<I: Hashable, H: Component>(id: I, header: H?, @CellsBuilder cells: () -> CellsBuildable) {
self.init(
id: id,
header: header.map(ViewNode.init),
Expand All @@ -163,7 +159,7 @@ public extension Section {
/// - footer: A footer component.
/// - cells: A closure that constructs cells.
@inlinable
init<I: Hashable, F: Component, C: CellsBuildable>(id: I, footer: F?, @CellsBuilder cells: () -> C) {
public init<I: Hashable, F: Component, C: CellsBuildable>(id: I, footer: F?, @CellsBuilder cells: () -> C) {
self.init(
id: id,
cells: cells().buildCells(),
Expand All @@ -177,7 +173,7 @@ public extension Section {
/// - id: An identifier to be wrapped.
/// - header: A header component.
@inlinable
init<I: Hashable, H: Component>(id: I, header: H?) {
public init<I: Hashable, H: Component>(id: I, header: H?) {
self.init(
id: id,
header: header.map(ViewNode.init)
Expand All @@ -190,16 +186,14 @@ public extension Section {
/// - id: An identifier to be wrapped.
/// - footer: A footer component.
@inlinable
init<I: Hashable, F: Component>(id: I, footer: F?) {
public init<I: Hashable, F: Component>(id: I, footer: F?) {
self.init(
id: id,
footer: footer.map(ViewNode.init)
)
}
}

#endif

extension Section: SectionsBuildable {
/// Build an array of section.
public func buildSections() -> [Section] {
Expand Down
14 changes: 12 additions & 2 deletions Tests/Adapters/UICollectionViewFlowLayoutAdapterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ final class UICollectionViewFlowLayoutAdapterTests: XCTestCase {
)
]

let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewLayout())
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
collectionView.dataSource = adapter
collectionView.delegate = adapter
collectionView.layoutIfNeeded()

func check(expectedClass: (UICollectionViewCell & ComponentRenderable).Type) {
let cell = adapter.collectionView(
Expand Down Expand Up @@ -324,7 +327,14 @@ final class UICollectionViewFlowLayoutAdapterTests: XCTestCase {
)
]

let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewLayout())
let layout = UICollectionViewFlowLayout()
layout.headerReferenceSize = CGSize(width: 100, height: 100)
layout.footerReferenceSize = CGSize(width: 100, height: 100)

let collectionView = UICollectionView(
frame: CGRect(x: 0, y: 0, width: 500, height: 500),
collectionViewLayout: layout
)
collectionView.dataSource = adapter
collectionView.delegate = adapter
collectionView.layoutIfNeeded()
Expand Down
4 changes: 0 additions & 4 deletions Tests/FunctionBuilder/CellsBuilderTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if swift(>=5.1)

import XCTest
@testable import Carbon

Expand Down Expand Up @@ -257,5 +255,3 @@ final class CellsBuilderTests: XCTestCase {
}
}
}

#endif
4 changes: 0 additions & 4 deletions Tests/FunctionBuilder/GroupTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if swift(>=5.1)

import XCTest
@testable import Carbon

Expand Down Expand Up @@ -93,5 +91,3 @@ final class GroupTests: XCTestCase {
XCTAssertEqual(sections[2].id, 2)
}
}

#endif
4 changes: 0 additions & 4 deletions Tests/FunctionBuilder/SectionsBuilderTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if swift(>=5.1)

import XCTest
@testable import Carbon

Expand Down Expand Up @@ -257,5 +255,3 @@ final class SectionsBuilderTests: XCTestCase {
}
}
}

#endif
Loading