├── .github └── FUNDING.yml ├── Assets └── uikit_uilabel_preview.png ├── Example ├── SwiftUIKitExample │ ├── Assets.xcassets │ │ ├── Contents.json │ │ ├── AccentColor.colorset │ │ │ └── Contents.json │ │ ├── swiftlee_orange.colorset │ │ │ └── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Preview Content │ │ └── Preview Assets.xcassets │ │ │ └── Contents.json │ ├── SwiftUIKitExampleApp.swift │ ├── SwiftUIwithUIKitView.swift │ ├── Info.plist │ └── UIKitView.swift └── SwiftUIKitExample.xcodeproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── project.pbxproj ├── Tests └── SwiftUIKitViewTests │ └── SwiftUIKitViewTests.swift ├── .swiftpm └── xcode │ └── package.xcworkspace │ └── contents.xcworkspacedata ├── Package.swift ├── Sources └── SwiftUIKitView │ ├── KeyPathReferenceWritable.swift │ ├── SwiftUIViewConvertable.swift │ ├── UIViewContaining.swift │ ├── ModifiedUIViewContainer.swift │ ├── UIViewContainingCoordinator.swift │ ├── UIViewContainer.swift │ └── IntrinsicContentView.swift ├── LICENSE ├── .gitignore └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [AvdLee] 4 | -------------------------------------------------------------------------------- /Assets/uikit_uilabel_preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AvdLee/SwiftUIKitView/HEAD/Assets/uikit_uilabel_preview.png -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Tests/SwiftUIKitViewTests/SwiftUIKitViewTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import SwiftUIKitView 3 | 4 | final class SwiftUIKitViewTests: XCTestCase { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/SwiftUIKitExampleApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftUIKitExampleApp.swift 3 | // SwiftUIKitExample 4 | // 5 | // Created by Antoine van der Lee on 28/12/2020. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct SwiftUIKitExampleApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | SwiftUIwithUIKitView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/Assets.xcassets/swiftlee_orange.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0.227", 9 | "green" : "0.306", 10 | "red" : "0.933" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | } 15 | ], 16 | "info" : { 17 | "author" : "xcode", 18 | "version" : 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "SwiftUIKitView", 8 | platforms: [ 9 | .iOS(.v14), 10 | .macOS(.v10_15), 11 | .tvOS(.v14), 12 | .watchOS(.v6) 13 | ], 14 | products: [ 15 | .library( 16 | name: "SwiftUIKitView", 17 | targets: ["SwiftUIKitView"]), 18 | ], 19 | targets: [ 20 | .target( 21 | name: "SwiftUIKitView", 22 | dependencies: []), 23 | .testTarget( 24 | name: "SwiftUIKitViewTests", 25 | dependencies: ["SwiftUIKitView"]), 26 | ] 27 | ) 28 | -------------------------------------------------------------------------------- /Sources/SwiftUIKitView/KeyPathReferenceWritable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // KeyPathReferenceWritable.swift 3 | // 4 | // 5 | // Created by Antoine van der Lee on 28/12/2020. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Defines a type that is configurable using reference writeable keypaths. 11 | /// 12 | /// Example usage: 13 | /// 14 | /// UILabel() 15 | /// .set(\.text, to: "Example") 16 | 17 | public protocol KeyPathReferenceWritable { 18 | associatedtype T 19 | associatedtype U 20 | 21 | func set(_ keyPath: ReferenceWritableKeyPath, to value: Value) -> U 22 | } 23 | 24 | public extension KeyPathReferenceWritable { 25 | func set(_ keyPath: ReferenceWritableKeyPath, to value: Value) -> Self { 26 | self[keyPath: keyPath] = value 27 | return self 28 | } 29 | } 30 | 31 | /// Add inheritance for NSObject types to make the methods accessible for many default types. 32 | extension NSObject: KeyPathReferenceWritable { } 33 | -------------------------------------------------------------------------------- /Sources/SwiftUIKitView/SwiftUIViewConvertable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftUIViewConvertable.swift 3 | // 4 | // 5 | // Created by Antoine van der Lee on 28/12/2020. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | /// Defines a type that's convertible to a SwiftUI `View`. 12 | @available(iOS 13.0, *) 13 | public protocol SwiftUIViewConvertable { 14 | associatedtype View: UIView 15 | func swiftUIView(layout: Layout) -> UIViewContainer 16 | } 17 | 18 | /// Add default protocol comformance for `UIView` instances. 19 | extension UIView: SwiftUIViewConvertable {} 20 | 21 | @available(iOS 13.0, *) 22 | public extension SwiftUIViewConvertable where Self: UIView { 23 | func swiftUIView(layout: Layout) -> UIViewContainer { 24 | assert( 25 | ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1", 26 | "This method is designed to use in previews only and is not performant for production code. Use `UIViewContainer(, layout: layout)` instead." 27 | ) 28 | return UIViewContainer(self, layout: layout) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Antoine van der Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Sources/SwiftUIKitView/UIViewContaining.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewContaining.swift 3 | // 4 | // 5 | // Created by Antoine van der Lee on 23/07/2022. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | import SwiftUI 11 | 12 | public protocol UIViewContaining: UIViewRepresentable { 13 | associatedtype Child: UIView 14 | func set(_ keyPath: ReferenceWritableKeyPath, to value: Value) -> ModifiedUIViewContainer 15 | func update(_ uiView: Child, coordinator: UIViewContainingCoordinator, updateContentSize: Bool) 16 | } 17 | 18 | extension UIViewContaining { 19 | public func set(_ keyPath: ReferenceWritableKeyPath, to value: Value) -> ModifiedUIViewContainer { 20 | ModifiedUIViewContainer(child: self, keyPath: keyPath, value: value) 21 | } 22 | } 23 | 24 | public extension View { 25 | /// Creates a preview of the `UIViewContainer` with the right size applied. 26 | /// - Returns: A preview of the container. 27 | func preview(displayName: String? = nil) -> some View { 28 | return fixedSize() 29 | .previewLayout(.sizeThatFits) 30 | .previewDisplayName(displayName) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftUIKitView/ModifiedUIViewContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ModifiedUIViewContainer.swift 3 | // 4 | // 5 | // Created by Antoine van der Lee on 23/07/2022. 6 | // 7 | 8 | import Foundation 9 | import SwiftUI 10 | import UIKit 11 | 12 | public struct ModifiedUIViewContainer: UIViewContaining where ChildContainer.Child == Child { 13 | 14 | let child: ChildContainer 15 | let keyPath: ReferenceWritableKeyPath 16 | let value: Value 17 | 18 | public func makeCoordinator() -> UIViewContainingCoordinator { 19 | child.makeCoordinator() as! UIViewContainingCoordinator 20 | } 21 | 22 | public func makeUIView(context: Context) -> IntrinsicContentView { 23 | context.coordinator.createView() 24 | } 25 | 26 | public func updateUIView(_ uiView: IntrinsicContentView, context: Context) { 27 | update(uiView.contentView, coordinator: context.coordinator, updateContentSize: true) 28 | } 29 | 30 | public func update(_ uiView: Child, coordinator: UIViewContainingCoordinator, updateContentSize: Bool) { 31 | uiView[keyPath: keyPath] = value 32 | child.update(uiView, coordinator: coordinator, updateContentSize: false) 33 | 34 | if updateContentSize { 35 | coordinator.view?.updateContentSize() 36 | } 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Sources/SwiftUIKitView/UIViewContainingCoordinator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewContainingCoordinator.swift 3 | // 4 | // 5 | // Created by Antoine van der Lee on 23/07/2022. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | import SwiftUI 11 | 12 | /// The type of Layout to apply to the SwiftUI `View`. 13 | public enum Layout { 14 | 15 | /// Uses the size returned by .`systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)`. 16 | case intrinsic 17 | 18 | /// Uses an intrinsic height combined with a fixed width. 19 | case fixedWidth(width: CGFloat) 20 | 21 | /// A fixed width and height is used. 22 | case fixed(size: CGSize) 23 | } 24 | 25 | public class UIViewContainingCoordinator { 26 | private(set) var view: IntrinsicContentView? 27 | private var viewCreator: () -> Child 28 | 29 | var widthConstraint: NSLayoutConstraint? 30 | var heightConstraint: NSLayoutConstraint? 31 | private let layout: Layout 32 | 33 | init(_ viewCreator: @escaping () -> Child, layout: Layout) { 34 | self.viewCreator = viewCreator 35 | self.layout = layout 36 | } 37 | 38 | func createView() -> IntrinsicContentView { 39 | if let view = view { 40 | return view 41 | } else { 42 | let contentView = IntrinsicContentView(contentView: viewCreator(), layout: layout) 43 | view = contentView 44 | return contentView 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/SwiftUIwithUIKitView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftUIwithUIKitView.swift 3 | // SwiftUIKitExample 4 | // 5 | // Created by Antoine van der Lee on 28/12/2020. 6 | // 7 | 8 | import SwiftUI 9 | import SwiftUIKitView 10 | 11 | struct SwiftUIwithUIKitView: View { 12 | @State var integer: Int = 0 13 | 14 | var body: some View { 15 | NavigationView { 16 | VStack { 17 | // Use UIKit inside SwiftUI like this: 18 | UIViewContainer(UIKitView(), layout: .intrinsic) 19 | .set(\.title, to: "Hello, UIKit \(integer)!") 20 | .set(\.backgroundColor, to: UIColor(named: "swiftlee_orange")) 21 | .fixedSize() 22 | .navigationTitle("Use UIKit in SwiftUI") 23 | 24 | Button("RANDOMIZED: \(integer)") { 25 | integer = Int.random(in: 0..<300) 26 | } 27 | } 28 | } 29 | } 30 | } 31 | 32 | struct SwiftUIwithUIKitView_Previews: PreviewProvider { 33 | static var previews: some View { 34 | SwiftUIwithUIKitView() 35 | } 36 | } 37 | 38 | // MARK: - UILabel Preview Example 39 | struct UILabelExample_Preview: PreviewProvider { 40 | static var previews: some View { 41 | UILabel() // <- This is a `UIKit` view. 42 | .swiftUIView(layout: .intrinsic) // <- This is a SwiftUI `View`. 43 | .set(\.text, to: "Hello, UIKit!") // <- Use key paths for updates. 44 | .fixedSize() // <- Make sure the size is set 45 | .previewLayout(.sizeThatFits) 46 | .previewDisplayName("UILabel Preview Example") 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | 28 | UIApplicationSupportsIndirectInputEvents 29 | 30 | UILaunchScreen 31 | 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Sources/SwiftUIKitView/UIViewContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewContainer.swift 3 | // 4 | // 5 | // Created by Antoine van der Lee on 28/12/2020. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | import SwiftUI 11 | 12 | /// A container for UIKit `UIView` elements. Conforms to the `UIViewRepresentable` protocol to allow conversion into SwiftUI `View`s. 13 | @available(iOS 13.0, *) 14 | public struct UIViewContainer { 15 | 16 | let viewCreator: () -> Child 17 | let layout: Layout 18 | 19 | /// Initializes a `UIViewContainer` 20 | /// - Parameters: 21 | /// - view: `UIView` being previewed 22 | /// - layout: The layout to apply on the `UIView`. Defaults to `intrinsic`. 23 | public init(_ viewCreator: @escaping @autoclosure () -> Child, layout: Layout = .intrinsic) { 24 | self.viewCreator = viewCreator 25 | self.layout = layout 26 | } 27 | } 28 | 29 | // MARK: Preview + UIViewRepresentable 30 | 31 | @available(iOS 13, *) 32 | extension UIViewContainer: UIViewRepresentable { 33 | public func makeCoordinator() -> UIViewContainingCoordinator { 34 | // Create an instance of Coordinator 35 | Coordinator(viewCreator, layout: layout) 36 | } 37 | 38 | public func makeUIView(context: Context) -> IntrinsicContentView { 39 | context.coordinator.createView() 40 | } 41 | 42 | public func updateUIView(_ view: IntrinsicContentView, context: Context) { 43 | update(view.contentView, coordinator: context.coordinator, updateContentSize: true) 44 | 45 | } 46 | } 47 | 48 | extension UIViewContainer: UIViewContaining { 49 | public func update(_ uiView: Child, coordinator: UIViewContainingCoordinator, updateContentSize: Bool) { 50 | guard updateContentSize else { return } 51 | coordinator.view?.updateContentSize() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample/UIKitView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIKitView.swift 3 | // SwiftUIKitExample 4 | // 5 | // Created by Antoine van der Lee on 28/12/2020. 6 | // 7 | 8 | import UIKit 9 | import SwiftUI 10 | 11 | /// Previews are easier now too: 12 | struct UIKitView_Previews: PreviewProvider { 13 | static var previews: some View { 14 | UIKitView() 15 | .swiftUIView(layout: .intrinsic) 16 | .set(\.title, to: "This is a UIView") 17 | .preview(displayName: "A UIKit UIView preview") 18 | } 19 | } 20 | 21 | /// An example `UIKit` view to demonstrate `SwiftUIKitView`. 22 | /// Represents a simple overlay view with a rounded black background and a text label. 23 | final class UIKitView: UIView { 24 | 25 | private lazy var newLabel: UILabel = { 26 | let label = UILabel() 27 | label.textColor = .white 28 | label.numberOfLines = 1 29 | label.font = .systemFont(ofSize: 12) 30 | label.translatesAutoresizingMaskIntoConstraints = false 31 | return label 32 | }() 33 | 34 | /// The title to display on the overlay. 35 | var title: String? { 36 | get { 37 | newLabel.text 38 | } 39 | set { 40 | newLabel.text = newValue 41 | } 42 | } 43 | 44 | convenience init() { 45 | self.init(frame: .zero) 46 | } 47 | 48 | override init(frame: CGRect) { 49 | super.init(frame: frame) 50 | setupView() 51 | 52 | print("INIT") 53 | } 54 | 55 | required init?(coder: NSCoder) { 56 | fatalError("init(coder:) has not been implemented") 57 | } 58 | 59 | private func setupView() { 60 | translatesAutoresizingMaskIntoConstraints = false 61 | backgroundColor = UIColor.black.withAlphaComponent(0.7) 62 | layer.cornerRadius = 5.0 63 | layoutMargins = .init(top: 4, left: 10, bottom: 4, right: 10) 64 | addSubview(newLabel) 65 | 66 | NSLayoutConstraint.activate([ 67 | newLabel.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor), 68 | newLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor), 69 | layoutMarginsGuide.bottomAnchor.constraint(equalTo: newLabel.bottomAnchor), 70 | layoutMarginsGuide.trailingAnchor.constraint(equalTo: newLabel.trailingAnchor) 71 | ]) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Sources/SwiftUIKitView/IntrinsicContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IntrinsicContentView.swift 3 | // 4 | // 5 | // Created by Antoine van der Lee on 23/07/2022. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | public final class IntrinsicContentView: UIView { 12 | let contentView: ContentView 13 | let layout: Layout 14 | 15 | init(contentView: ContentView, layout: Layout) { 16 | self.contentView = contentView 17 | self.layout = layout 18 | 19 | super.init(frame: .zero) 20 | backgroundColor = .clear 21 | addSubview(contentView) 22 | clipsToBounds = true 23 | } 24 | 25 | @available(*, unavailable) required init?(coder _: NSCoder) { 26 | fatalError("init(coder:) has not been implemented") 27 | } 28 | 29 | private var contentSize: CGSize = .zero { 30 | didSet { 31 | invalidateIntrinsicContentSize() 32 | } 33 | } 34 | 35 | public override var intrinsicContentSize: CGSize { 36 | switch layout { 37 | case .intrinsic: 38 | return contentSize 39 | case .fixedWidth(let width): 40 | return .init(width: width, height: contentSize.height) 41 | case .fixed(let size): 42 | return size 43 | } 44 | } 45 | 46 | public func updateContentSize() { 47 | switch layout { 48 | case .fixedWidth(let width): 49 | // Set the frame of the cell, so that the layout can be updated. 50 | var newFrame = contentView.frame 51 | newFrame.size = CGSize(width: width, height: UIView.layoutFittingExpandedSize.height) 52 | contentView.frame = newFrame 53 | 54 | // Make sure the contents of the cell have the correct layout. 55 | contentView.setNeedsLayout() 56 | contentView.layoutIfNeeded() 57 | 58 | // Get the size of the cell 59 | let computedSize = contentView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) 60 | 61 | // Apple: "Only consider the height for cells, because the contentView isn't anchored correctly sometimes." We use ceil to make sure we get rounded numbers and no half pixels. 62 | contentSize = CGSize(width: width, height: ceil(computedSize.height)) 63 | case .fixed(let size): 64 | contentSize = size 65 | case .intrinsic: 66 | contentSize = contentView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftUIKitView 2 | ![Swift Version](https://img.shields.io/badge/Swift-5.5-F16D39.svg?style=flat) ![Dependency frameworks](https://img.shields.io/badge/Supports-_Swift_Package_Manager-F16D39.svg?style=flat) [![Twitter](https://img.shields.io/badge/twitter-@Twannl-blue.svg?style=flat)](https://twitter.com/twannl) 3 | 4 | Easily use UIKit views in SwiftUI. 5 | 6 | - Convert `UIView` to SwiftUI `View` 7 | - Create Xcode Previews from `UIView` elements 8 | - SwiftUI functional updating `UIView` properties using a protocol with [Associated Types](https://www.avanderlee.com/swift/associated-types-protocols/). 9 | 10 | You can read more about [Getting started with UIKit in SwiftUI and visa versa](https://www.avanderlee.com/swiftui/integrating-swiftui-with-uikit/). 11 | 12 | ## Examples 13 | 14 | ### Using SwiftUIKitView in Production Code 15 | Using a `UIKit` view directly in SwiftUI for production code requires you to use: 16 | 17 | ```swift 18 | UIViewContainer(, layout: ) 19 | ``` 20 | 21 | This is to prevent a UIKit view from being redrawn on every SwiftUI view redraw. 22 | 23 | ```swift 24 | import SwiftUI 25 | import SwiftUIKitView 26 | 27 | struct SwiftUIwithUIKitView: View { 28 | var body: some View { 29 | NavigationView { 30 | UIViewContainer(UILabel(), layout: .intrinsic) // <- This can be any `UIKit` view. 31 | .set(\.text, to: "Hello, UIKit!") // <- Use key paths for updates. 32 | .set(\.backgroundColor, to: UIColor(named: "swiftlee_orange")) 33 | .fixedSize() 34 | .navigationTitle("Use UIKit in SwiftUI") 35 | } 36 | } 37 | } 38 | ``` 39 | 40 | ### Using `SwiftUIKitView` in Previews 41 | Performance in Previews is less important, it's being redrawn either way. 42 | 43 | Therefore, you can use the more convenient `swiftUIView()` modifier: 44 | 45 | ```swift 46 | UILabel() // <- This is a `UIKit` view. 47 | .swiftUIView(layout: .intrinsic) // <- This is returning a SwiftUI `View`. 48 | ``` 49 | 50 | Creating a preview provider for a `UIView` looks as follows: 51 | 52 | ```swift 53 | import SwiftUI 54 | import SwiftUIKitView 55 | 56 | struct UILabelExample_Preview: PreviewProvider { 57 | static var previews: some View { 58 | UILabel() // <- This is a `UIKit` view. 59 | .swiftUIView(layout: .intrinsic) // <- This is a SwiftUI `View`. 60 | .set(\.text, to: "Hello, UIKit!") // <- Use key paths for updates. 61 | .fixedSize() // <- Make sure the size is set 62 | .previewLayout(.sizeThatFits) 63 | .previewDisplayName("UILabel Preview Example") 64 | } 65 | } 66 | ``` 67 | 68 | Which results in the following preview: 69 | 70 | 71 | 72 | ### KeyPath updating 73 | 74 | This framework also comes with a `KeyPathReferenceWritable` protocol that allows to update objects using functions and writable KeyPath references: 75 | 76 | ```swift 77 | /// Defines a type that is configurable using reference writeable keypaths. 78 | public protocol KeyPathReferenceWritable { 79 | associatedtype T 80 | associatedtype U 81 | 82 | func set(_ keyPath: ReferenceWritableKeyPath, to value: Value) -> U 83 | } 84 | 85 | public extension KeyPathReferenceWritable { 86 | func set(_ keyPath: ReferenceWritableKeyPath, to value: Value) -> Self { 87 | self[keyPath: keyPath] = value 88 | return self 89 | } 90 | } 91 | 92 | /// Add inheritance for NSObject types to make the methods accessible for many default types. 93 | extension NSObject: KeyPathReferenceWritable { } 94 | ``` 95 | 96 | This can be used as follows: 97 | 98 | ```swift 99 | UILabel() 100 | .set(\.text, to: "Example") 101 | ``` 102 | 103 | And allows to easily build up SwiftUI style view configurations to keep the same readability when working in SwiftUI. 104 | 105 | ## Installation 106 | 107 | ### Swift Package Manager 108 | 109 | The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but this SDK does support its use on supported platforms. 110 | 111 | Once you have your Swift package set up, adding the SDK as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. 112 | 113 | ```swift 114 | dependencies: [ 115 | .package(url: "https://github.com/AvdLee/SwiftUIKitView.git", .upToNextMajor(from: "2.0.0")) 116 | ] 117 | ``` 118 | 119 | ## Communication 120 | 121 | - If you **found a bug**, open an [issue](https://github.com/AvdLee/SwiftUIKitView/issues). 122 | - If you **have a feature request**, open an [issue](https://github.com/AvdLee/SwiftUIKitView/issues). 123 | - If you **want to contribute**, submit a [pull request](https://github.com/AvdLee/SwiftUIKitView/pulls). 124 | 125 | 126 | ## License 127 | 128 | **SwiftUIKitView** is available under the MIT license, and uses source code from open source projects. See the [LICENSE](https://github.com/AvdLee/SwiftUIKitView/blob/main/LICENSE) file for more info. 129 | 130 | ## Author 131 | 132 | This project is originally created by [Antoine van der Lee](https://www.twitter.com/twannl). I'm open for contributions of any kind to make this project even better. 133 | -------------------------------------------------------------------------------- /Example/SwiftUIKitExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 84E8FEC8259A167F00891910 /* SwiftUIKitExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E8FEC7259A167F00891910 /* SwiftUIKitExampleApp.swift */; }; 11 | 84E8FECA259A167F00891910 /* SwiftUIwithUIKitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E8FEC9259A167F00891910 /* SwiftUIwithUIKitView.swift */; }; 12 | 84E8FECC259A168000891910 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84E8FECB259A168000891910 /* Assets.xcassets */; }; 13 | 84E8FECF259A168000891910 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84E8FECE259A168000891910 /* Preview Assets.xcassets */; }; 14 | 84E8FEDC259A171600891910 /* SwiftUIKitView in Frameworks */ = {isa = PBXBuildFile; productRef = 84E8FEDB259A171600891910 /* SwiftUIKitView */; }; 15 | 84E8FEDF259A173400891910 /* UIKitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E8FEDE259A173400891910 /* UIKitView.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 84E8FEC4259A167F00891910 /* SwiftUIKitExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftUIKitExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 84E8FEC7259A167F00891910 /* SwiftUIKitExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIKitExampleApp.swift; sourceTree = ""; }; 21 | 84E8FEC9259A167F00891910 /* SwiftUIwithUIKitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIwithUIKitView.swift; sourceTree = ""; }; 22 | 84E8FECB259A168000891910 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 84E8FECE259A168000891910 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 24 | 84E8FED0259A168000891910 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | 84E8FED8259A169B00891910 /* SwiftUIKitView */ = {isa = PBXFileReference; lastKnownFileType = folder; name = SwiftUIKitView; path = ../..; sourceTree = ""; }; 26 | 84E8FEDE259A173400891910 /* UIKitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitView.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 84E8FEC1259A167F00891910 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | 84E8FEDC259A171600891910 /* SwiftUIKitView in Frameworks */, 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | 84E8FEBB259A167F00891910 = { 42 | isa = PBXGroup; 43 | children = ( 44 | 84E8FEC6259A167F00891910 /* SwiftUIKitExample */, 45 | 84E8FEC5259A167F00891910 /* Products */, 46 | 84E8FEDA259A171600891910 /* Frameworks */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 84E8FEC5259A167F00891910 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 84E8FEC4259A167F00891910 /* SwiftUIKitExample.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 84E8FEC6259A167F00891910 /* SwiftUIKitExample */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 84E8FED8259A169B00891910 /* SwiftUIKitView */, 62 | 84E8FEC7259A167F00891910 /* SwiftUIKitExampleApp.swift */, 63 | 84E8FEC9259A167F00891910 /* SwiftUIwithUIKitView.swift */, 64 | 84E8FECB259A168000891910 /* Assets.xcassets */, 65 | 84E8FED0259A168000891910 /* Info.plist */, 66 | 84E8FECD259A168000891910 /* Preview Content */, 67 | 84E8FEDE259A173400891910 /* UIKitView.swift */, 68 | ); 69 | path = SwiftUIKitExample; 70 | sourceTree = ""; 71 | }; 72 | 84E8FECD259A168000891910 /* Preview Content */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 84E8FECE259A168000891910 /* Preview Assets.xcassets */, 76 | ); 77 | path = "Preview Content"; 78 | sourceTree = ""; 79 | }; 80 | 84E8FEDA259A171600891910 /* Frameworks */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | ); 84 | name = Frameworks; 85 | sourceTree = ""; 86 | }; 87 | /* End PBXGroup section */ 88 | 89 | /* Begin PBXNativeTarget section */ 90 | 84E8FEC3259A167F00891910 /* SwiftUIKitExample */ = { 91 | isa = PBXNativeTarget; 92 | buildConfigurationList = 84E8FED3259A168000891910 /* Build configuration list for PBXNativeTarget "SwiftUIKitExample" */; 93 | buildPhases = ( 94 | 84E8FEC0259A167F00891910 /* Sources */, 95 | 84E8FEC1259A167F00891910 /* Frameworks */, 96 | 84E8FEC2259A167F00891910 /* Resources */, 97 | ); 98 | buildRules = ( 99 | ); 100 | dependencies = ( 101 | ); 102 | name = SwiftUIKitExample; 103 | packageProductDependencies = ( 104 | 84E8FEDB259A171600891910 /* SwiftUIKitView */, 105 | ); 106 | productName = SwiftUIKitExample; 107 | productReference = 84E8FEC4259A167F00891910 /* SwiftUIKitExample.app */; 108 | productType = "com.apple.product-type.application"; 109 | }; 110 | /* End PBXNativeTarget section */ 111 | 112 | /* Begin PBXProject section */ 113 | 84E8FEBC259A167F00891910 /* Project object */ = { 114 | isa = PBXProject; 115 | attributes = { 116 | LastSwiftUpdateCheck = 1230; 117 | LastUpgradeCheck = 1230; 118 | TargetAttributes = { 119 | 84E8FEC3259A167F00891910 = { 120 | CreatedOnToolsVersion = 12.3; 121 | }; 122 | }; 123 | }; 124 | buildConfigurationList = 84E8FEBF259A167F00891910 /* Build configuration list for PBXProject "SwiftUIKitExample" */; 125 | compatibilityVersion = "Xcode 9.3"; 126 | developmentRegion = en; 127 | hasScannedForEncodings = 0; 128 | knownRegions = ( 129 | en, 130 | Base, 131 | ); 132 | mainGroup = 84E8FEBB259A167F00891910; 133 | productRefGroup = 84E8FEC5259A167F00891910 /* Products */; 134 | projectDirPath = ""; 135 | projectRoot = ""; 136 | targets = ( 137 | 84E8FEC3259A167F00891910 /* SwiftUIKitExample */, 138 | ); 139 | }; 140 | /* End PBXProject section */ 141 | 142 | /* Begin PBXResourcesBuildPhase section */ 143 | 84E8FEC2259A167F00891910 /* Resources */ = { 144 | isa = PBXResourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | 84E8FECF259A168000891910 /* Preview Assets.xcassets in Resources */, 148 | 84E8FECC259A168000891910 /* Assets.xcassets in Resources */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXResourcesBuildPhase section */ 153 | 154 | /* Begin PBXSourcesBuildPhase section */ 155 | 84E8FEC0259A167F00891910 /* Sources */ = { 156 | isa = PBXSourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | 84E8FEDF259A173400891910 /* UIKitView.swift in Sources */, 160 | 84E8FECA259A167F00891910 /* SwiftUIwithUIKitView.swift in Sources */, 161 | 84E8FEC8259A167F00891910 /* SwiftUIKitExampleApp.swift in Sources */, 162 | ); 163 | runOnlyForDeploymentPostprocessing = 0; 164 | }; 165 | /* End PBXSourcesBuildPhase section */ 166 | 167 | /* Begin XCBuildConfiguration section */ 168 | 84E8FED1259A168000891910 /* Debug */ = { 169 | isa = XCBuildConfiguration; 170 | buildSettings = { 171 | ALWAYS_SEARCH_USER_PATHS = NO; 172 | CLANG_ANALYZER_NONNULL = YES; 173 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 174 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 175 | CLANG_CXX_LIBRARY = "libc++"; 176 | CLANG_ENABLE_MODULES = YES; 177 | CLANG_ENABLE_OBJC_ARC = YES; 178 | CLANG_ENABLE_OBJC_WEAK = YES; 179 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 180 | CLANG_WARN_BOOL_CONVERSION = YES; 181 | CLANG_WARN_COMMA = YES; 182 | CLANG_WARN_CONSTANT_CONVERSION = YES; 183 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 184 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 185 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 186 | CLANG_WARN_EMPTY_BODY = YES; 187 | CLANG_WARN_ENUM_CONVERSION = YES; 188 | CLANG_WARN_INFINITE_RECURSION = YES; 189 | CLANG_WARN_INT_CONVERSION = YES; 190 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 191 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 192 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 194 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 195 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 196 | CLANG_WARN_STRICT_PROTOTYPES = YES; 197 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 198 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 199 | CLANG_WARN_UNREACHABLE_CODE = YES; 200 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 201 | COPY_PHASE_STRIP = NO; 202 | DEBUG_INFORMATION_FORMAT = dwarf; 203 | ENABLE_STRICT_OBJC_MSGSEND = YES; 204 | ENABLE_TESTABILITY = YES; 205 | GCC_C_LANGUAGE_STANDARD = gnu11; 206 | GCC_DYNAMIC_NO_PIC = NO; 207 | GCC_NO_COMMON_BLOCKS = YES; 208 | GCC_OPTIMIZATION_LEVEL = 0; 209 | GCC_PREPROCESSOR_DEFINITIONS = ( 210 | "DEBUG=1", 211 | "$(inherited)", 212 | ); 213 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 214 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 215 | GCC_WARN_UNDECLARED_SELECTOR = YES; 216 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 217 | GCC_WARN_UNUSED_FUNCTION = YES; 218 | GCC_WARN_UNUSED_VARIABLE = YES; 219 | IPHONEOS_DEPLOYMENT_TARGET = 14.3; 220 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 221 | MTL_FAST_MATH = YES; 222 | ONLY_ACTIVE_ARCH = YES; 223 | SDKROOT = iphoneos; 224 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 225 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 226 | }; 227 | name = Debug; 228 | }; 229 | 84E8FED2259A168000891910 /* Release */ = { 230 | isa = XCBuildConfiguration; 231 | buildSettings = { 232 | ALWAYS_SEARCH_USER_PATHS = NO; 233 | CLANG_ANALYZER_NONNULL = YES; 234 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_ENABLE_OBJC_WEAK = YES; 240 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 241 | CLANG_WARN_BOOL_CONVERSION = YES; 242 | CLANG_WARN_COMMA = YES; 243 | CLANG_WARN_CONSTANT_CONVERSION = YES; 244 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 246 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 247 | CLANG_WARN_EMPTY_BODY = YES; 248 | CLANG_WARN_ENUM_CONVERSION = YES; 249 | CLANG_WARN_INFINITE_RECURSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 252 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 253 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 254 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 255 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 256 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 257 | CLANG_WARN_STRICT_PROTOTYPES = YES; 258 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 259 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 260 | CLANG_WARN_UNREACHABLE_CODE = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | COPY_PHASE_STRIP = NO; 263 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 264 | ENABLE_NS_ASSERTIONS = NO; 265 | ENABLE_STRICT_OBJC_MSGSEND = YES; 266 | GCC_C_LANGUAGE_STANDARD = gnu11; 267 | GCC_NO_COMMON_BLOCKS = YES; 268 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 269 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 270 | GCC_WARN_UNDECLARED_SELECTOR = YES; 271 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 272 | GCC_WARN_UNUSED_FUNCTION = YES; 273 | GCC_WARN_UNUSED_VARIABLE = YES; 274 | IPHONEOS_DEPLOYMENT_TARGET = 14.3; 275 | MTL_ENABLE_DEBUG_INFO = NO; 276 | MTL_FAST_MATH = YES; 277 | SDKROOT = iphoneos; 278 | SWIFT_COMPILATION_MODE = wholemodule; 279 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 280 | VALIDATE_PRODUCT = YES; 281 | }; 282 | name = Release; 283 | }; 284 | 84E8FED4259A168000891910 /* Debug */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 288 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 289 | CODE_SIGN_STYLE = Automatic; 290 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUIKitExample/Preview Content\""; 291 | DEVELOPMENT_TEAM = 4QMDKC8VLJ; 292 | ENABLE_PREVIEWS = YES; 293 | INFOPLIST_FILE = SwiftUIKitExample/Info.plist; 294 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 295 | LD_RUNPATH_SEARCH_PATHS = ( 296 | "$(inherited)", 297 | "@executable_path/Frameworks", 298 | ); 299 | PRODUCT_BUNDLE_IDENTIFIER = com.swiftlee.SwiftUIKitExample; 300 | PRODUCT_NAME = "$(TARGET_NAME)"; 301 | SWIFT_VERSION = 5.0; 302 | TARGETED_DEVICE_FAMILY = "1,2"; 303 | }; 304 | name = Debug; 305 | }; 306 | 84E8FED5259A168000891910 /* Release */ = { 307 | isa = XCBuildConfiguration; 308 | buildSettings = { 309 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 310 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 311 | CODE_SIGN_STYLE = Automatic; 312 | DEVELOPMENT_ASSET_PATHS = "\"SwiftUIKitExample/Preview Content\""; 313 | DEVELOPMENT_TEAM = 4QMDKC8VLJ; 314 | ENABLE_PREVIEWS = YES; 315 | INFOPLIST_FILE = SwiftUIKitExample/Info.plist; 316 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 317 | LD_RUNPATH_SEARCH_PATHS = ( 318 | "$(inherited)", 319 | "@executable_path/Frameworks", 320 | ); 321 | PRODUCT_BUNDLE_IDENTIFIER = com.swiftlee.SwiftUIKitExample; 322 | PRODUCT_NAME = "$(TARGET_NAME)"; 323 | SWIFT_VERSION = 5.0; 324 | TARGETED_DEVICE_FAMILY = "1,2"; 325 | }; 326 | name = Release; 327 | }; 328 | /* End XCBuildConfiguration section */ 329 | 330 | /* Begin XCConfigurationList section */ 331 | 84E8FEBF259A167F00891910 /* Build configuration list for PBXProject "SwiftUIKitExample" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | 84E8FED1259A168000891910 /* Debug */, 335 | 84E8FED2259A168000891910 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | 84E8FED3259A168000891910 /* Build configuration list for PBXNativeTarget "SwiftUIKitExample" */ = { 341 | isa = XCConfigurationList; 342 | buildConfigurations = ( 343 | 84E8FED4259A168000891910 /* Debug */, 344 | 84E8FED5259A168000891910 /* Release */, 345 | ); 346 | defaultConfigurationIsVisible = 0; 347 | defaultConfigurationName = Release; 348 | }; 349 | /* End XCConfigurationList section */ 350 | 351 | /* Begin XCSwiftPackageProductDependency section */ 352 | 84E8FEDB259A171600891910 /* SwiftUIKitView */ = { 353 | isa = XCSwiftPackageProductDependency; 354 | productName = SwiftUIKitView; 355 | }; 356 | /* End XCSwiftPackageProductDependency section */ 357 | }; 358 | rootObject = 84E8FEBC259A167F00891910 /* Project object */; 359 | } 360 | --------------------------------------------------------------------------------