From dba744d5585f6870f0e5eeecd8346ab401b89a89 Mon Sep 17 00:00:00 2001 From: Eugene Date: Tue, 16 Nov 2021 20:09:04 +0200 Subject: [PATCH] Display a single counter value --- UIKit-to-SwiftUI.xcodeproj/project.pbxproj | 8 +++---- UIKit-to-SwiftUI/CounterView.swift | 25 ++++++++++++++++++++++ UIKit-to-SwiftUI/SwiftUIView.swift | 20 ----------------- 3 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 UIKit-to-SwiftUI/CounterView.swift delete mode 100644 UIKit-to-SwiftUI/SwiftUIView.swift diff --git a/UIKit-to-SwiftUI.xcodeproj/project.pbxproj b/UIKit-to-SwiftUI.xcodeproj/project.pbxproj index 258a88f..a58ecd9 100644 --- a/UIKit-to-SwiftUI.xcodeproj/project.pbxproj +++ b/UIKit-to-SwiftUI.xcodeproj/project.pbxproj @@ -13,7 +13,7 @@ 14D2E4D42742E2EC0043AC2B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 14D2E4D22742E2EC0043AC2B /* Main.storyboard */; }; 14D2E4D62742E2ED0043AC2B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 14D2E4D52742E2ED0043AC2B /* Assets.xcassets */; }; 14D2E4D92742E2ED0043AC2B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 14D2E4D72742E2ED0043AC2B /* LaunchScreen.storyboard */; }; - 14D2E4E2274429090043AC2B /* SwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D2E4E1274429090043AC2B /* SwiftUIView.swift */; }; + 14D2E4E2274429090043AC2B /* CounterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D2E4E1274429090043AC2B /* CounterView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -26,7 +26,7 @@ 14D2E4D52742E2ED0043AC2B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 14D2E4D82742E2ED0043AC2B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 14D2E4DA2742E2ED0043AC2B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 14D2E4E1274429090043AC2B /* SwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIView.swift; sourceTree = ""; }; + 14D2E4E1274429090043AC2B /* CounterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -67,7 +67,7 @@ 14D2E4D52742E2ED0043AC2B /* Assets.xcassets */, 14D2E4D72742E2ED0043AC2B /* LaunchScreen.storyboard */, 14D2E4DA2742E2ED0043AC2B /* Info.plist */, - 14D2E4E1274429090043AC2B /* SwiftUIView.swift */, + 14D2E4E1274429090043AC2B /* CounterView.swift */, ); path = "UIKit-to-SwiftUI"; sourceTree = ""; @@ -144,7 +144,7 @@ files = ( 14D2E4D12742E2EC0043AC2B /* ViewController.swift in Sources */, 14D2E4CD2742E2EC0043AC2B /* AppDelegate.swift in Sources */, - 14D2E4E2274429090043AC2B /* SwiftUIView.swift in Sources */, + 14D2E4E2274429090043AC2B /* CounterView.swift in Sources */, 14D2E4CF2742E2EC0043AC2B /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/UIKit-to-SwiftUI/CounterView.swift b/UIKit-to-SwiftUI/CounterView.swift new file mode 100644 index 0000000..fe642e1 --- /dev/null +++ b/UIKit-to-SwiftUI/CounterView.swift @@ -0,0 +1,25 @@ +// +// CounterView.swift +// UIKit-to-SwiftUI +// +// Created by u on 16.11.21. +// + +import SwiftUI + +struct CounterView: View { + var counter = 0 + + var body: some View { + Text("Counter: \(counter)") + } +} + +struct SwiftUIView_Previews: PreviewProvider { + static var previews: some View { + ForEach([0, 42], id: \.self) { counter in + CounterView(counter: counter) + .previewLayout(.fixed(width: 200, height: 100)) + } + } +} diff --git a/UIKit-to-SwiftUI/SwiftUIView.swift b/UIKit-to-SwiftUI/SwiftUIView.swift deleted file mode 100644 index b5f13dd..0000000 --- a/UIKit-to-SwiftUI/SwiftUIView.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// SwiftUIView.swift -// UIKit-to-SwiftUI -// -// Created by u on 16.11.21. -// - -import SwiftUI - -struct SwiftUIView: View { - var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) - } -} - -struct SwiftUIView_Previews: PreviewProvider { - static var previews: some View { - SwiftUIView() - } -}