Post

Replies

Boosts

Views

Activity

PhotosPicker won't appear when it embedded in popover
When I embedded a PhotosPickerView() in popover, it won't works: struct PhotoPickerTest: View { @State private var selectedPhotoItem: PhotosPickerItem? @State var isTaped: Bool = false var body: some View { Button("", systemImage: "plus") { isTaped = true } .popover(isPresented: $isTaped) { PhotoPickerView() } } func PhotoPickerView() -> some View { PhotosPicker(selection: $selectedPhotoItem) { Image(systemName: "photo") } } } but if I just replace "popover" to "sheet", it works fine: struct PhotoPickerTest: View { @State private var selectedPhotoItem: PhotosPickerItem? @State var isTaped: Bool = false var body: some View { Button("", systemImage: "plus") { isTaped = true } .sheet(isPresented: $isTaped) { PhotoPickerView() } } func PhotoPickerView() -> some View { PhotosPicker(selection: $selectedPhotoItem) { Image(systemName: "photo") } } } I think it's a bug, and bothered me a lot, hope apple engineers can fix it.
3
0
888
Jan ’24
Help: scorllTo() doesn't works in VStack
I can read the scrollPosition correctly, but scrollTo() doesn't work. iOS 17, Xcode 15.2. Code like this below(can directly copy and paste): import SwiftUI struct PositionTest: View { @State private var weathers = Weather.samples @State private var scrollPosition: Weather.ID? @State private var isTaped: Bool = false var body: some View { VStack { Text("Scroll Position: " + (scrollPosition ?? "Cupertino")) if !isTaped { CollapsedView( weathers: $weathers, scrollPosition: $scrollPosition, isTaped: $isTaped ) } else { ExpandedView( weathers: $weathers, scrollPosition: $scrollPosition, isTaped: $isTaped ) } } .font(.title) .fontWeight(.semibold) .animation(.default, value: isTaped) } } #Preview { PositionTest() } struct CollapsedView: View { @Binding var weathers: [Weather] @Binding var scrollPosition: Weather.ID? @Binding var isTaped: Bool var body: some View { ScrollViewReader { proxy in ScrollView { VStack(spacing: 20) { ForEach(weathers) { weather in Text(weather.name) .frame(width: 350, height: 227) .foregroundStyle(.white) .background(.blue.gradient) .cornerRadius(40) .id(weather.id as Weather.ID?) .onTapGesture { isTaped.toggle() } } } .frame(maxWidth: .infinity) .scrollTargetLayout() } .scrollIndicators(.hidden) .scrollTargetBehavior(.viewAligned) .scrollPosition(id: $scrollPosition, anchor: .center) .onAppear { proxy.scrollTo(scrollPosition, anchor: .center) } } } } struct ExpandedView: View { @Binding var weathers: [Weather] @Binding var scrollPosition: Weather.ID? @Binding var isTaped: Bool var body: some View { ScrollViewReader { proxy in ScrollView { VStack(spacing: 20) { ForEach(weathers) { weather in Text(weather.name) .frame(width: 250, height: 227) .foregroundStyle(.white) .background(.indigo.gradient) .clipShape(.circle) .id(weather.id as Weather.ID?) .onTapGesture { isTaped.toggle() } } } .frame(maxWidth: .infinity) .scrollTargetLayout() } .scrollIndicators(.hidden) .scrollTargetBehavior(.viewAligned) .scrollPosition(id: $scrollPosition, anchor: .center) .onAppear { proxy.scrollTo(scrollPosition, anchor: .center) } } } } struct Weather: Identifiable { var id: String { name } let name: String let temp: Int static let samples = [ Weather(name: "Cupertino", temp: 12), Weather(name: "New York", temp: 13), Weather(name: "ShangHai", temp: 14), Weather(name: "London", temp: 15), Weather(name: "Las Vegas", temp: 16), ] } I found if I simply change the VStack to LazyVStack in both CollapsedView() and ExpandedView(), the scrollTo() method works fine. But in my project, for some reason I don't want to use LazyVStack, just want to use VStack, is there any way to make scorllTo() works in VStack?
0
0
630
Jan ’24
Swift Data how to get binding from @Query property?
I want to use List(data:, editActions:, rowContent:), the data: needs a $property, but I can't pass $persons in there directly. Is there any way to solve like this below: import SwiftUI import SwiftData struct BindableTest: View { @Environment(\.modelContext) var modelContext @Query var persons: [Person] var body: some View { VStack { Button("Add") { let person = Person(name: "test", age: 12) modelContext.insert(person) } List($persons, editActions: .all) { $person in Text(person.name) Text(person.age.formatted()) } } } } iOS 17
0
3
946
Feb ’24
ScrollView Bug
If put a List in ScrollVIew, List won't appear: import SwiftUI struct BugView: View { let numbers: [Int] = [0, 1, 2] var body: some View { ScrollView { List(numbers, id: \.self) { number in Text(number.description) } } } } #Preview { BugView() }
1
0
470
Apr ’24
What is the info property of SwiftUI::Layer
What is the info property of SwiftUI::Layer? I couldn't find any document or resource about it. It appears in SwiftUI::Layer's definition: struct Layer { metal::texture2d<half> tex; float2 info[5]; /// Samples the layer at `p`, in user-space coordinates, /// interpolating linearly between pixel values. Returns an RGBA /// pixel value, with color components premultipled by alpha (i.e. /// [R*A, G*A, B*A, A]), in the layer's working color space. half4 sample(float2 p) const { p = metal::fma(p.x, info[0], metal::fma(p.y, info[1], info[2])); p = metal::clamp(p, info[3], info[4]); return tex.sample(metal::sampler(metal::filter::linear), p); } };
0
1
698
Jun ’24
SwiftUI [[stichable]] metal shader & CIFilter written in metal extern"C" can't work at the same time
In my project, I used two metal shaders in two ways. One is link to SwiftUI's modifier .colorEffect(ShaderLibrary.myShader()), which metal shader marked as [[stichable]]. Another one is a custom CIFilter, which kernel been written in external "C" closure. Because custom CIFilter must add build rules so Xcode can compile it, so I added -fcikernel to Metal Compiler and -cikernel to Metal Linker from Build Settings, just like Apple's document told me that. But the result is weird, if I add rules, custom CIFilter works, [[stichable]] shader doesn't work. if I delete rules, and comment out code of CIFilter(for avoiding warning), [[stichable]] shader works, but now I can't use my custom CIFilter. Actually, once these two shaders works well in my project, but when I updated Xcode from 15 to 16, it became weird, the 2 shaders can't exist at same time. Even though I go back to Xcode 15, I can't save them. I have no idea, please help, thank you. XCode 16 / iOS 18 on iPhone 14 Pro
2
0
800
Sep ’24
VisionOS doesn't support offer code?
I want to create offer code for my Vision app, but I didn't find that option in Apple Connect subscription price page. And when I check that from my iPhone app page, I saw the offer code description "Codes for discounted prices or free offers are unique alphanumeric codes that can be easily distributed using physical or digital channels for your iOS app and macOS app. Your customers can redeem them on devices running iOS 14, iPadOS 14, macOS 15 or later through the App Store redemption flow or within the app if you've implemented the presentCodeRedemptionSheet StoreKit API. You can create codes for up to 10 active offers at a time." It doesn't mentioned VisionOS, so can I set offer code for my Vision app?
0
0
289
Dec ’24
How to search location in global rather than in local?
I'm doing a weather app, users can search locations for getting weather, but the problem is, the results only shows locations in my country, not in global. For example, I'm in China, I can't search New York, it just shows nothing. Here's my code: @Observable class SearchPlaceManager: NSObject { var searchText: String = "" let searchCompleter = MKLocalSearchCompleter() var searchResults: [MKLocalSearchCompletion] = [] override init() { super.init() searchCompleter.resultTypes = .address searchCompleter.delegate = self } @MainActor func seachLocation() { if !searchText.isEmpty { searchCompleter.queryFragment = searchText } } } extension SearchPlaceManager: MKLocalSearchCompleterDelegate { func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) { withAnimation { self.searchResults = completer.results } } } Also, I've tried to set searchCompleter.region = MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 0, longitude: 0), span: MKCoordinateSpan(latitudeDelta: 180, longitudeDelta: 360) ), but it doesn't work.
2
0
826
Dec ’24
PhotosPicker won't appear when it embedded in popover
When I embedded a PhotosPickerView() in popover, it won't works: struct PhotoPickerTest: View { @State private var selectedPhotoItem: PhotosPickerItem? @State var isTaped: Bool = false var body: some View { Button("", systemImage: "plus") { isTaped = true } .popover(isPresented: $isTaped) { PhotoPickerView() } } func PhotoPickerView() -&gt; some View { PhotosPicker(selection: $selectedPhotoItem) { Image(systemName: "photo") } } } but if I just replace "popover" to "sheet", it works fine: struct PhotoPickerTest: View { @State private var selectedPhotoItem: PhotosPickerItem? @State var isTaped: Bool = false var body: some View { Button("", systemImage: "plus") { isTaped = true } .sheet(isPresented: $isTaped) { PhotoPickerView() } } func PhotoPickerView() -&gt; some View { PhotosPicker(selection: $selectedPhotoItem) { Image(systemName: "photo") } } } I think it's a bug, and bothered me a lot, hope apple engineers can fix it.
Replies
3
Boosts
0
Views
888
Activity
Jan ’24
How to pass scrollTransition's phase value to my @State property
.scrollTransition { view, phase in view.opacity(phase.isIdentity ? 1 : 0) .scaleEffect(phase.isIdentity ? 1 : 0.75) } Is there anyway to pass the phase.isIdentity to my @State bool property? iOS 17
Replies
0
Boosts
0
Views
431
Activity
Jan ’24
Help: scorllTo() doesn't works in VStack
I can read the scrollPosition correctly, but scrollTo() doesn't work. iOS 17, Xcode 15.2. Code like this below(can directly copy and paste): import SwiftUI struct PositionTest: View { @State private var weathers = Weather.samples @State private var scrollPosition: Weather.ID? @State private var isTaped: Bool = false var body: some View { VStack { Text("Scroll Position: " + (scrollPosition ?? "Cupertino")) if !isTaped { CollapsedView( weathers: $weathers, scrollPosition: $scrollPosition, isTaped: $isTaped ) } else { ExpandedView( weathers: $weathers, scrollPosition: $scrollPosition, isTaped: $isTaped ) } } .font(.title) .fontWeight(.semibold) .animation(.default, value: isTaped) } } #Preview { PositionTest() } struct CollapsedView: View { @Binding var weathers: [Weather] @Binding var scrollPosition: Weather.ID? @Binding var isTaped: Bool var body: some View { ScrollViewReader { proxy in ScrollView { VStack(spacing: 20) { ForEach(weathers) { weather in Text(weather.name) .frame(width: 350, height: 227) .foregroundStyle(.white) .background(.blue.gradient) .cornerRadius(40) .id(weather.id as Weather.ID?) .onTapGesture { isTaped.toggle() } } } .frame(maxWidth: .infinity) .scrollTargetLayout() } .scrollIndicators(.hidden) .scrollTargetBehavior(.viewAligned) .scrollPosition(id: $scrollPosition, anchor: .center) .onAppear { proxy.scrollTo(scrollPosition, anchor: .center) } } } } struct ExpandedView: View { @Binding var weathers: [Weather] @Binding var scrollPosition: Weather.ID? @Binding var isTaped: Bool var body: some View { ScrollViewReader { proxy in ScrollView { VStack(spacing: 20) { ForEach(weathers) { weather in Text(weather.name) .frame(width: 250, height: 227) .foregroundStyle(.white) .background(.indigo.gradient) .clipShape(.circle) .id(weather.id as Weather.ID?) .onTapGesture { isTaped.toggle() } } } .frame(maxWidth: .infinity) .scrollTargetLayout() } .scrollIndicators(.hidden) .scrollTargetBehavior(.viewAligned) .scrollPosition(id: $scrollPosition, anchor: .center) .onAppear { proxy.scrollTo(scrollPosition, anchor: .center) } } } } struct Weather: Identifiable { var id: String { name } let name: String let temp: Int static let samples = [ Weather(name: "Cupertino", temp: 12), Weather(name: "New York", temp: 13), Weather(name: "ShangHai", temp: 14), Weather(name: "London", temp: 15), Weather(name: "Las Vegas", temp: 16), ] } I found if I simply change the VStack to LazyVStack in both CollapsedView() and ExpandedView(), the scrollTo() method works fine. But in my project, for some reason I don't want to use LazyVStack, just want to use VStack, is there any way to make scorllTo() works in VStack?
Replies
0
Boosts
0
Views
630
Activity
Jan ’24
Swift Data how to get binding from @Query property?
I want to use List(data:, editActions:, rowContent:), the data: needs a $property, but I can't pass $persons in there directly. Is there any way to solve like this below: import SwiftUI import SwiftData struct BindableTest: View { @Environment(\.modelContext) var modelContext @Query var persons: [Person] var body: some View { VStack { Button("Add") { let person = Person(name: "test", age: 12) modelContext.insert(person) } List($persons, editActions: .all) { $person in Text(person.name) Text(person.age.formatted()) } } } } iOS 17
Replies
0
Boosts
3
Views
946
Activity
Feb ’24
ScrollView Bug
If put a List in ScrollVIew, List won't appear: import SwiftUI struct BugView: View { let numbers: [Int] = [0, 1, 2] var body: some View { ScrollView { List(numbers, id: \.self) { number in Text(number.description) } } } } #Preview { BugView() }
Replies
1
Boosts
0
Views
470
Activity
Apr ’24
What is the info property of SwiftUI::Layer
What is the info property of SwiftUI::Layer? I couldn't find any document or resource about it. It appears in SwiftUI::Layer's definition: struct Layer { metal::texture2d<half> tex; float2 info[5]; /// Samples the layer at `p`, in user-space coordinates, /// interpolating linearly between pixel values. Returns an RGBA /// pixel value, with color components premultipled by alpha (i.e. /// [R*A, G*A, B*A, A]), in the layer's working color space. half4 sample(float2 p) const { p = metal::fma(p.x, info[0], metal::fma(p.y, info[1], info[2])); p = metal::clamp(p, info[3], info[4]); return tex.sample(metal::sampler(metal::filter::linear), p); } };
Replies
0
Boosts
1
Views
698
Activity
Jun ’24
SwiftUI [[stichable]] metal shader & CIFilter written in metal extern"C" can't work at the same time
In my project, I used two metal shaders in two ways. One is link to SwiftUI's modifier .colorEffect(ShaderLibrary.myShader()), which metal shader marked as [[stichable]]. Another one is a custom CIFilter, which kernel been written in external "C" closure. Because custom CIFilter must add build rules so Xcode can compile it, so I added -fcikernel to Metal Compiler and -cikernel to Metal Linker from Build Settings, just like Apple's document told me that. But the result is weird, if I add rules, custom CIFilter works, [[stichable]] shader doesn't work. if I delete rules, and comment out code of CIFilter(for avoiding warning), [[stichable]] shader works, but now I can't use my custom CIFilter. Actually, once these two shaders works well in my project, but when I updated Xcode from 15 to 16, it became weird, the 2 shaders can't exist at same time. Even though I go back to Xcode 15, I can't save them. I have no idea, please help, thank you. XCode 16 / iOS 18 on iPhone 14 Pro
Replies
2
Boosts
0
Views
800
Activity
Sep ’24
VisionOS doesn't support offer code?
I want to create offer code for my Vision app, but I didn't find that option in Apple Connect subscription price page. And when I check that from my iPhone app page, I saw the offer code description "Codes for discounted prices or free offers are unique alphanumeric codes that can be easily distributed using physical or digital channels for your iOS app and macOS app. Your customers can redeem them on devices running iOS 14, iPadOS 14, macOS 15 or later through the App Store redemption flow or within the app if you've implemented the presentCodeRedemptionSheet StoreKit API. You can create codes for up to 10 active offers at a time." It doesn't mentioned VisionOS, so can I set offer code for my Vision app?
Replies
0
Boosts
0
Views
289
Activity
Dec ’24
How to search location in global rather than in local?
I'm doing a weather app, users can search locations for getting weather, but the problem is, the results only shows locations in my country, not in global. For example, I'm in China, I can't search New York, it just shows nothing. Here's my code: @Observable class SearchPlaceManager: NSObject { var searchText: String = "" let searchCompleter = MKLocalSearchCompleter() var searchResults: [MKLocalSearchCompletion] = [] override init() { super.init() searchCompleter.resultTypes = .address searchCompleter.delegate = self } @MainActor func seachLocation() { if !searchText.isEmpty { searchCompleter.queryFragment = searchText } } } extension SearchPlaceManager: MKLocalSearchCompleterDelegate { func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) { withAnimation { self.searchResults = completer.results } } } Also, I've tried to set searchCompleter.region = MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 0, longitude: 0), span: MKCoordinateSpan(latitudeDelta: 180, longitudeDelta: 360) ), but it doesn't work.
Replies
2
Boosts
0
Views
826
Activity
Dec ’24
Why VisionOS doesn't support CustomMaterial ?
It's much easier to use custom material to bridge metal shader onto Reality model than using LowLevelTexture does the same thing. Why VisionOS doesn't support this material:
Replies
1
Boosts
0
Views
160
Activity
Apr ’25
How to make device cross into portal world.
I want to step into portal world. I've know PortalCrossingComponent can make an entity to cross portal, but how to make device cross into portal world?
Replies
1
Boosts
0
Views
133
Activity
Apr ’25
How to export an entity to USD?
I want to record animation with entity, then export it to .usd without using Reality Composer Pro, how to achieve that?
Replies
1
Boosts
0
Views
74
Activity
Apr ’25
Can't build old project on Xcode 26 beta5
I have a visionOS 2 project created on Xcode 16, when I updated to Xcode 26 beta5, I can't build it any more, every time it stuck in process like the picture shows below: Already tried many methods to fix this issue, such as clear build folders, but don't work. MacBook Air M2 / MacOS 26 beta5 / Xcode 26 beta5
Replies
1
Boosts
0
Views
221
Activity
Aug ’25
Can't observe Entity's orientation properties in Slider
On Xcode 26 and visionOS 26, apple provides observable property for Entity, so we can easily interact with Entity between RealityScene and SwiftUI, but there is a issue: It's fine to observe Entity's position and scale properties in Slider, but can't observe orientation properties in Slider. MacBook Air M2 / Xcode 26 beta6
Replies
1
Boosts
0
Views
215
Activity
Aug ’25
How to give spatial photo a custom corner radius?
Spatial photo in RealityView has a default corner radius. I made a parallel effect with spatial photos in ScrollView(like Spatial Gallery), but the corner radius disappeared on left and right spatial photos. I've tried .clipShape and .mask modifiers, but they did't work. How to clip or mask spatial photo with corner radius effect?
Replies
0
Boosts
1
Views
481
Activity
Aug ’25