Where is Playgrounds 4? It's 2021-12-14 now...
Come on please!!!
We are looking forward to it!
Post not yet marked as solved
//
// ContentView.swift
// Shared
//
// Created by Abenx on 2021/8/8.
//
import SwiftUI
/// Demo of NavigationLink causing page problems
///
/// Problem description: When the following structure is used, after entering level3. If the app loses focus, such as drawing out of the control center or multi-page manager, it will cause the page to refresh and render, and eventually jump to level 2.
/// iPhone 12 Pro Max / iOS 15 beta 4 has this problem
/// iPhone 12 Pro Max / iOS 14.6 has no such problem
/// Xcode Version: 12.5.1 (12E507) & 13.0 beta 4 (13A5201i)
struct ContentView: View {
/// If you comment out this line of code, there will be no problem.
@Environment(\.openURL) var openURL
@State private var isOK: Bool = false
var body: some View {
NavigationView {
NavigationLink("Goto Level 2", destination: Level2View().onAppear {
/// If you comment out this line of code, there will be no problem.
isOK = false
})
}
}
}
struct Level2View: View {
var body: some View {
/// If you don't use GeometryReader, there is no problem.
GeometryReader {proxy in
NavigationLink("Goto Level 3", destination: Text("I am in Level 3"))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I found this way to take screenshot in full screen view of SwiftUI. But How to take screenshot of a ScrollView content view?
Thanks!
Normal way:
SwiftUI Extension
extension View {
func takeScreenshot(origin: CGPoint, size: CGSize) -> UIImage {
let window = UIWindow(frame: CGRect(origin: origin, size: size))
let hosting = UIHostingController(rootView: self)
window.rootViewController = hosting
window.makeKeyAndVisible()
return hosting.view.snapshotImage()!
}
}
Swift Extension
extension UIView {
func snapshotImage() -> UIImage {
.....
}
}
Post not yet marked as solved
Using Configuration.storekit to test storekit.
It works well when I run debug.
But not work at Previews of Xcode.
Post not yet marked as solved
Your CloudKit containers can’t be shown at this time. Try again later. Please file a bug and include the request ID eb93179f-6153-40f4-9b5b-9a7a8c99f763.
Post not yet marked as solved
I am new of SwiftUI, write ugly codes like that...
let actionContentView = VStack {
if UIDevice.current.userInterfaceIdiom == .phone {
Spacer()
}
...
}
...
return UIDevice.current.userInterfaceIdiom == .phone ? AnyView(VStack(spacing: 0) {
settingContentView
cameraContentView
actionContentView
}) : AnyView(ZStack(alignment: .top){
cameraContentView
VStack (spacing:0) {
settingContentView
Spacer()
actionContentView.padding(40)
}
})
...
return UIDevice.current.userInterfaceIdiom == .phone ? AnyView(GeometryReader(content: internalView(geometry:))
.background(BubbleBackground())) : AnyView(GeometryReader(content: internalView(geometry:))
.edgesIgnoringSafeArea(.all)
.background(BubbleBackground()))
How to use conditions to switch view properties gracefully?
Thanks!
I am a new swifter from objective-c.
In the code:
import SwiftUI
@main
struct MySwiftAppApp: App {
@SceneBuilder var body: some Scene {
WindowGroup {
NavigationView {
ContentView()
}
}
WKNotificationScene(controller: NotificationController.self, category: "LandmarkNear")
}
}
Here is no 'WKHostingController' yet.
So, How to using 'WCSessionDelegate'?
I tried like that:
import SwiftUI
import WatchConnectivity
struct WatchInfo: View {
@State private var showMessage: String = "Wating"
init() {
ABWatchSessionManager.sharedInstance.addDelegateObject(WatchSessionDelegate())
}
var body: some View {
Text(showMessage)
}
class WatchSessionDelegate: NSObject, WCSessionDelegate {
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
let data: Dictionary<String, String> = message["data"] as! Dictionary<String, String>
if data["dataType"] == DataType.ping.rawValue {
} else if data["dataType"] == DataType.data.rawValue {
}
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
}
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
}
}
}
struct WatchInfo_Previews: PreviewProvider {
static var previews: some View {
WatchInfo()
}
}
Is it the best way to using Delegate in SwiftUI-only code?
And how can I changing the 'showMessage'?
Thanks!
Post not yet marked as solved
See the SwiftUI tutorials:
https://developer.apple.com/tutorials/swiftui/creating-a-macos-app
Un-star all the landmarks and click "Favorites only" will got a error
But I change the code "NavigationPrimary.swift"
LandmarkList(
selectedLandmark: $selectedLandmark,
filter: $filter
)
.listStyle(SidebarListStyle())
to
LandmarkList(
selectedLandmark: $selectedLandmark,
filter: $filter
)
.listStyle(InsetListStyle())
It works well.
So, What's the different of "InsetListStyle" and "SidebarListStyle"?
If I want to use "SidebarListStyle", how to fix it?
Thanks!
PS:
This is my code, fix some bugs in the tutorials
https://github.com/rushairer/MySwiftApp
Post not yet marked as solved
https://developer.apple.com/tutorials/swiftui/working-with-ui-controls
Button action in List causes event bubbling error.
I tried fix it: https://github.com/rushairer/MySwiftApp/commit/8d9578f07a4e55d061f779f44bf20d113f642bd5
Using 'onTapGesture' instead of Button
macOS 10.16 beta
Using Xcode Version 11.5 (11E608c) will get error when distribute app to app store:
"Profile doesn't include the com.apple.application-identifier entitlement."
Using Xcode Version 12.0 beta (12A6159) will be OK.
But, I can not distribute app with Beta version Xcode...
Help~~me~~!
How to use the same code (e.g. common librarieswith application?