Post

Replies

Boosts

Views

Activity

Reply to APNS key download issue
Hello :) That‘s interesting because I had the exact same issue a few months ago and I haven‘t found a solution for it yet. I can’t remember if I changed anything but it worked for me after I tried it again a few hours later… maybe it just needs some time to really revoke the first key.
Apr ’24
Reply to Main thread blocked using AVPlayer in SwiftUI
Hello :) First things first: that piece of code is working on a fast internet connection, and I don't get any error message. As far as I can tell, the problem is that the loading process is placed to the Main Thread. That causes some blocking on slow internet connections. Some others had the same issue (more to find here). You can try to use this: struct ContentView: View { @State private var player = AVPlayer() var videoUrl: String = "https://video.twimg.com/amplify_video/1760315643142750208/vid/avc1/640x360/-1etorSK7w2g9Nlc.mp4?tag=16" var body: some View { VideoPlayer(player: player) .task { player = AVPlayer(url: URL(string: videoUrl)!) } } } Please let me now, if this fixes your error message. If not, we will find a solution.
Apr ’24
Reply to Using .environment() for Observable Object
Hello :) I would recommend you to use the .environment(). Therefore you create one instance of your ViewModel in order to handle it through the hierarchy to be accessible whenever it is necessary. Apple shows us with this example: @main struct BookReaderApp: App { @State private var library = Library() var body: some Scene { WindowGroup { LibraryView() .environment(library) } } } And for the LibraryView(): struct LibraryView: View { @Environment(Library.self) private var library var body: some View { List(library.books) { book in BookView(book: book) } } } You can find more information here. If you have any further questions don’t hesitate to ask.
Mar ’24
Reply to Maximise Image above Form
Hello :) That's a really interesting question. I tried many things but I only found two different approaches. The problem is, you don't get the form's height itself in any way because a form always takes as much vertical space as it gets. So that's why you could fix the height of the image, so that there is enough space for the form with its content. The drawback of this solution is, that if the content in the form gets more and more, it's not visible anymore when it gets too much. It would be something like: Image(systemName: "gear") .resizable() .scaledToFit() Form { Section("section 1") { Text("text 1") Text("text 2") Text("text 3") } Section("section 2") { Text("text 1") Text("text 2") Text("text 3") } } .scrollDisabled(true) .frame(height: 500) //added the .frame() modifier Another approach would be to not use the Form. By using a normal VStack with the .layoutPriority() modifier the image gets maximized dynamically and the VStack adjusts its height itself. The advantage is that you can fill the VStack with any content you want and the image resizes itself. Example would be: Image(systemName: "gear") .resizable() .scaledToFit() VStack { ForEach(1..<9) { value in HStack { Text("Test + " + value.description) Spacer() } .padding(.leading) .padding(.bottom, 4) } } .layoutPriority(1) //very important, otherwise it won't work Maybe someone else found another solution but I think the second approach might be the best way to start in order to see everything good and adjusted on any device. If you have any further questions, don't hesitate to ask :)
Feb ’24
Reply to No preview when creating new project
Hello Andrea :) there seems to be a problem with the certificates. Try to go to the top left corner, click "Xcode", then go to "Settings" and then choose "Accounts". Your Apple-ID should be listed there. Click the button "Download Manual Profiles". Try to restart Xcode. Maybe it is working then. I hope, this might help.
Feb ’24
Reply to Var of type color inside swift data model
Hello :) SwiftData only supports primitive types (Int, Bool, ...) currently, so there is no possibility to save a color itself at the moment. In order to save a color you can choose different approaches. For example, you could define a SwiftData Model to save the different values of red, green, blue and alpha like this: final class ColorModel { var red: CGFloat var green: CGFloat var blue: CGFloat var alpha: CGFloat init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { self.red = red self.green = green self.blue = blue self.alpha = alpha } } Then you can display your colors through the following code (simplified here in a ForEach(), has to be adjusted): ForEach(colors, id: \.self) { color in Color(UIColor(red: color.red, green: color.green, blue: color.blue, alpha: color.alpha)) } If you have any further questions, don't hesitate to ask. I hope I was able to help you.
Feb ’24