Post

Replies

Boosts

Views

Activity

Reply to Online data to swift UI
There's a bunch of ways to do this. Let me explain a few ideas I've got... If your website is using some sort of Content Management System (CMS), then it likely already provides a JSON file that contains this information. You could download that file, interrogate the various parts of it and determine where the important information is held for what your app needs, then load the thumbnail images, headlines and preview text from there. If it doesn't use a CMS, someone somewhere (you) is always going to have to create this file of metadata. If I were you I'd have it as part of the website/hosting, and your app should download that file. I wouldn't put it in the app itself because you'd have to update the app - which is labour-intensive, and pointless. (We don't have to download a new copy of Apple's News app every time there's a new story.) What you would do with the JSON file downloaded from the website is take the relevant bits from it, then add the image, headline, preview text to an array of articles in the app, and display those in your view. I'd say sort it by article date descending, and limit how many you put in the view. When a user taps one of the articles, you would then download the full article from the website. It wouldn't make any sense to download the full article as part of the JSON file as the user might not view it. Be sure to implement error handling if you can't reach the website to download the data. And don't download data you already have, i.e. only download article data for articles after the most recent date in your list of articles. For example, if you have two articles already downloaded in the app, and they're dated last Monday and last Tuesday, if the JSON file now contains an article for today, you would only bother downloading today's article. If you're going to limit the number of articles shown your view, then your array can be a FIFO stack, i.e. first in first out. If you want to retain 20 articles then you would remove the oldest article from the array and add a new one into it. Because you're sorting the data in the view anyway there is no need to handling rotating the data in the array, i.e. no need to delete item 0 and move item 1 into slot 0, 2 into slot 1 etc. Hope this helps.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’24
Reply to ViewDidLoad in SwiftUI
I think both task and onAppear are executed before the view is displayed, so you can use either. A quick internet search suggests this page has some good examples: https://byby.dev/swiftui-task-vs-onappear
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’24
Reply to ViewDidLoad in SwiftUI
If you don't want to use .task as recommended by the Apple employee before me, then you might want to implement something like an .onFirstAppear so it's only executed once. Something like this should work: private struct OnFirstAppear: ViewModifier { let perform: () -> Void @State private var firstTime = true func body(content: Content) -> some View { content.onAppear { if firstTime { firstTime = false perform() } } } } extension View { func onFirstAppear(perform: @escaping () -> Void) -> some View { modifier(OnFirstAppear(perform: perform)) } } Use it as you would use .onAppear.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’24
Reply to Crash on TextField
Have you raised a Feedback report? If not, please do so at https://www.apple.com/feedback/ then post the FB number here. In all cases, you must raise the bug first, then you can, if you like, inform us on here, but we're just third-party developers like you. We have no input into when Apple deal with issues, and the best way to let Apple know there's an issue is to tell Apple about it by raising a Feedback report.
Topic: UI Frameworks SubTopic: UIKit
Jul ’24
Reply to Music displaying in Apple Watch SE
Break this down a little for us: What is "auto launch"? And where are you turning it off? Where is music being displayed on your Watch, and when? Why would turning off something called "auto launch" stop Music being displayed somewhere on a Watch? These two things don't seem related. Also... These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding. These forums are NOT where Apple's actual developers chat about stuff. Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Jul ’24