Posts

Post marked as solved
1 Replies
145 Views
In the new Swift Playground App format, we can share code between an iPad's Playground and Mac's Xcode. But some key behaviors are inconsistent. For example, using Xcode/iPad Playground to new a Test "Swift Playground App" and adding the following code. We'll see "1" on Xcode while "2" on iPad Playground App Test.swiftpm struct ContentView: View {   var body: some View {     #if SWIFT_PACKAGE     Text("1") // Using Xcode to open     #else     Text("2") // Using iPad Playground App to open     #endif   } } I think for a Swift Playground App, they should both to be "1"
Posted
by KyleYe.
Last updated
.
Post not yet marked as solved
1 Replies
1.2k Views
I was trying to use UIPasteboard.general.url to get some content, and I found that UIPasteboard.general.string could get the Universal Clipboard (other  devices' clipboard like Mac's and iPad's) while UIPasteboard.general.url could only get the local Clipboard. Below is a simply way to reproduce (in SwiftUI) Button(Text("getURL")){ print("url is \(UIPasteboard.general.url)") print("string is \(UIPasteboard.general.string)") } First you copy this link (actually any url string is OK) in Mac http://pic1.win4000.com/wallpaper/2019-08-05/5d47e530bcf01.jpg . And click the above button in your iOS device, you'll see something like this in your log url is nil string is Optional("http://pic1.win4000.com/wallpaper/2019-08-05/5d47e530bcf01.jpg") 2. Second you simply paste it into your iOS device(Universal Clipboard on) and copy it so that your local pasteboard have this content. And then click the above button in your iOS device, you'll see something like this in your log url is Optional("http://pic1.win4000.com/wallpaper/2019-08-05/5d47e530bcf01.jpg") string is Optional("http://pic1.win4000.com/wallpaper/2019-08-05/5d47e530bcf01.jpg")
Posted
by KyleYe.
Last updated
.
Post not yet marked as solved
0 Replies
1.7k Views
Description I have the following code in a working project, after migrating from SwiftUI1.0 to SwiftUI2.0, it behaves abnormally. // @Published var backgroundImage:UIImage? XXView() .onReceive(document.$backgroundImage) { image in zoomToFit(image, in: geometry.size) } In the old SwiftUI 1.0(Xcode 11.5), this will normally work and will be triggered once when launching the View. (Because backgroundImage is nil at first and then get inited) But in SwiftUI2.0(Xcode 12.0 beta2), this will not work and it zoomToFit will be triggered twice when launching the View. In zoomToFit function, I printed the size of image and geometry size, here is the result // Xcode 11.5 Optional((284.0, 177.0)) (0.0, 0.0) // Xcode 12.0 beta2 Optional((284.0, 177.0)) (0.0, 0.0) Optional((284.0, 177.0)) (414.0, 647.69091796875) Reproduce Below is a simply way to reproduce New a project If you are creating this using Xcode 12, remember to choose lifeCycle to UIKit App Delegate(easy to work with both Xcode version) - Add the following to ContentView.swift import SwiftUI class Store: ObservableObject { &#9;&#9;@Published var image = 2 } struct ContentView: View { &#9;&#9;@ObservedObject var store = Store() &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;NavigationView { &#9;&#9;&#9;&#9;&#9;&#9;List(0 ..< 5) { _ in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;NavigationLink( &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;destination: Text("destination") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.onReceive(self.store.$image) { _ in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("1") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;label: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("test") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } And you'll find it will print "1" once in old Xcode 11.5 while print "1" twice in Xcode 12.0 beta2
Posted
by KyleYe.
Last updated
.