ChatBot icon indicating copy to clipboard operation
ChatBot copied to clipboard

Error during build in ChatBoxApp.swift

Open gorbypark opened this issue 3 years ago • 9 comments

Hello! I came across your project and decided to try and build it. I am running into an error in ChatBotApp.swift, Missing argument for parameter #1 in call and Closure containing control flow statement cannot be used with result builder 'SceneBuilder'

The errors are being thrown in the block of code.

        .conditionally {
            if #available(macOS 13.0, *) {
                $0.defaultSize(width: 1000, height: 800)
            }
        }

Any ideas? I'd love to check out your app if I can get it to build.

Thanks!

gorbypark avatar Mar 07 '23 17:03 gorbypark

same issue, it compiles correctly if you comment that out though. Only issue is you won't have a predefined width and height of the window on launch, but at least it works.

ale-benassi avatar Mar 08 '23 16:03 ale-benassi

I also stumbled upon this issue but managed to find an alternative solution that keeps the default size. Applying the following patch, the application compiles and works as expected:

diff --git a/ChatBot/ChatBotApp.swift b/ChatBot/ChatBotApp.swift
index c2e2cb1..44c5c0a 100644
--- a/ChatBot/ChatBotApp.swift
+++ b/ChatBot/ChatBotApp.swift
@@ -53,9 +53,15 @@ struct ChatBotApp: App {
             }
         }
         .conditionally {
-            if #available(macOS 13.0, *) {
-                $0.defaultSize(width: 1000, height: 800)
-            }
+            setDefaultSize($0)
+        }
+    }
+
+    private func setDefaultSize(_ scene: some Scene) -> some Scene {
+        if #available(macOS 13.0, *) {
+            return scene.defaultSize(width: 1000, height: 800)
+        } else {
+            return scene
         }
     }
 }

I am not sure if there is a more elegant way to achieve the same outcome. If you want to test this patch and previously launched the application, remember to remove the container (i.e., ~/Library/Containers/ChatBot) first as .defaultSize only affects the first launch.

dnlfrst avatar Mar 08 '23 18:03 dnlfrst

Ooops, seems like I forgot to push my local changes to Github. I'm sorry for that. I'm pushing it now.

LiYanan2004 avatar Mar 09 '23 06:03 LiYanan2004

The problem is if #available statement is now available on Xcode 14.4 beta. This is a new feature for SceneBuilder. I just use it for convenience but forgot this version of Xcode is still in beta. So sorry for that.

LiYanan2004 avatar Mar 09 '23 06:03 LiYanan2004

I also stumbled upon this issue but managed to find an alternative solution that keeps the default size. Applying the following patch, the application compiles and works as expected:

diff --git a/ChatBot/ChatBotApp.swift b/ChatBot/ChatBotApp.swift
index c2e2cb1..44c5c0a 100644
--- a/ChatBot/ChatBotApp.swift
+++ b/ChatBot/ChatBotApp.swift
@@ -53,9 +53,15 @@ struct ChatBotApp: App {
             }
         }
         .conditionally {
-            if #available(macOS 13.0, *) {
-                $0.defaultSize(width: 1000, height: 800)
-            }
+            setDefaultSize($0)
+        }
+    }
+
+    private func setDefaultSize(_ scene: some Scene) -> some Scene {
+        if #available(macOS 13.0, *) {
+            return scene.defaultSize(width: 1000, height: 800)
+        } else {
+            return scene
         }
     }
 }

I am not sure if there is a more elegant way to achieve the same outcome. If you want to test this patch and previously launched the application, remember to remove the container (i.e., ~/Library/Containers/ChatBot) first as .defaultSize only affects the first launch.

This is a good way. But finally, I remove the default size.

LiYanan2004 avatar Mar 09 '23 06:03 LiYanan2004

@solid-pixel @dnlfrst @gorbypark Fixed. Please update your clone and try it again. If the issue is gone, please close the issue. Thanks. And sorry again for my mistake.🥹

LiYanan2004 avatar Mar 09 '23 06:03 LiYanan2004

@LiYanan2004 you have nothing to apologize for you've done a tremendous job with this app, thanks a lot!

ale-benassi avatar Mar 09 '23 15:03 ale-benassi

@solid-pixel Thanks

LiYanan2004 avatar Mar 09 '23 23:03 LiYanan2004

The fix works as expected, @LiYanan2004 feel free to close the issue. This is only possible as a contributor/maintainer, so you have to do this. 😉

dnlfrst avatar Mar 11 '23 11:03 dnlfrst