Post not yet marked as solved
what do i need to add for the .Overlay(Group {
Post not yet marked as solved
Could you please show me an example of a complete project that shows how to create Children Interactive books in Swift UI or Playground with links to various pages of the book that i can follow step-by-step?
Post not yet marked as solved
I'm following the Swift Tutorial, and everything is working ok until I create the LandmarkRow.swift
I keep getting the "Cannot Preview in This File" error, even after copying and pasting the code from the tutorial.
Any ideas?
Post not yet marked as solved
Bouncing from top to bottom won’t work properly. It’s working only when load some content more than screen height size… iOS14!
But, on iOS 15 all work like created
Post not yet marked as solved
Hi there, I am trying to upload my AR experience from Reality Composer into XCode using Swift. Although I have followed the documentation from Apple's presentation, minute 40:53, (https://developer.apple.com/videos/play/wwdc2019/609/?time=2453) of working with AR and XCode, I receive an error message every time I try to load my scene, as the load prompt seems to become part of the scene title and my title itself is not recognized. For example: Module '...' has no member named 'load...'.
If anyone can help me here, I would be very grateful.
Post not yet marked as solved
The ios14 to run my app, it is no problem.
when run my app on the ios13.7 . The Xcode's console print an ERROR : EXC_BAD_SCCESS
I look for the web for this question,but i can't find answer for this question .
if you know answer ,write down your answer,please.
Thank you!
Post not yet marked as solved
Hello forum!
I have a grid in my app
I want to display 1 column if the user's device is iPhone
or 2 columns if the device is an iPad
How can I do that from SwiftUI?
Could you help me? thankS
Post not yet marked as solved
I have a current app in the store written in Objective C that works OK, but I want to update it via SwiftUI as a universal app.
In my original app, I adjust the display brightness for night time use by setting UIScreen.main.brightness = 0.2 for example. When exiting the application, I return it to its previous value.
I have been unable to find out how this can be done in SwiftUI.
Anyone know?
Post not yet marked as solved
SwiftUI promise is to call View’s body only when needed to avoid invalidating views whose State has not changed.
However, there are some cases when this promise is not kept and the View is updated even though its state has not changed.
Example:
struct InsideView: View {
@Binding var value: Int
// …
}
Looking at that view, we’d expect that its body is called when the value changes. However, this is not always true and it depends on how that binding is passed to the view.
When the view is created this way, everything works as expected and InsideView is not updated when value hasn’t changed.
@State private var value: Int = 0
InsideView(value: $value)
In the example below, InsideView will be incorrectly updated even when value has not changed. It will be updated whenever its container is updated too.
var customBinding: Binding<Int> {
Binding<Int> { 100 } set: { _ in }
}
InsideView(value: customBinding)
Can anyone explain this and say whether it's expected? Is there any way to avoid this behaviour that can ultimately lead to performance issues?
Here's a sample project if anyone wants to play with it:
import SwiftUI
struct ContentView: View {
@State private var tab = 0
@State private var count = 0
@State private var someValue: Int = 100
var customBinding: Binding<Int> {
Binding<Int> { 100 } set: { _ in }
}
var body: some View {
VStack {
Picker("Tab", selection: $tab) {
Text("@Binding from @State").tag(0)
Text("Custom @Binding").tag(1)
}
.pickerStyle(SegmentedPickerStyle())
VStack(spacing: 10) {
if tab == 0 {
Text("When you tap a button, a view below should not be updated. That's a desired behaviour.")
InsideView(value: $someValue)
} else if tab == 1 {
Text("When you tap a button, a view below will be updated (its background color will be set to random value to indicate this). This is unexpected because the view State has not changed.")
InsideView(value: customBinding)
}
}
.frame(width: 250, height: 150)
Button("Tap! Count: \(count)") {
count += 1
}
}
.frame(width: 300, height: 350)
.padding()
}
}
struct InsideView: View {
@Binding var value: Int
var body: some View {
print("[⚠️] InsideView body.")
return VStack {
Text("I'm a child view. My body should be called only once.")
.multilineTextAlignment(.center)
Text("Value: \(value)")
}
.background(Color.random)
}
}
extension ShapeStyle where Self == Color {
static var random: Color {
Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
)
}
}
Post not yet marked as solved
When using conditionals in view bodies, can I preserve identity between the true and false sides of the conditional by adding an explicit id?
struct DogTreat: Identifiable {
var expirationDate: Date
var serialID: String
var id: String { serialID }
}
...
struct WrapperView: View {
...
var treat: DogTreat
var isExpired: Bool { treat.expirationDate < .now }
var body: some View {
if isExpired {
DogTreatView(treat)
.id(treat.id)
.opacity(0.75)
else {
DogTreatView(treat)
.id(treat.id)
}
}
...
}
Does this perform / behave the same as
struct WrapperView: View {
...
var treat: DogTreat
var isExpired: Bool { treat.expirationDate < .now }
var body: some View {
DogTreatView(treat)
.opacity(isExpired ? 0.75 : 1.0)
}
...
}