Post

Replies

Boosts

Views

Activity

Reply to Help me understand the View Protocol
Is Body placeholder replaced with the actual View type? Not exactly. When you create a new file in your project and select SwiftUI View, Xcode creates the file with a View compliant structure stub. The type of that structure will be what you named the file when you created it, and its body property returns some View. What does "Self.Body" means? Self refers to a type, where self refers to an initialized instance of the type. So, if you name your SwiftUI view "MyView" then Self.Body will be MyView.body which is of type some View which is an opaque return type. An opaque return type in this case just means that it is some kind of view that conforms to the View protocol. It could be of a type provided by the framework or a custom type.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to Is it me or is SwiftUI on macOS just awful?
No, you're not alone. How the hell are we supposed to localize the mac App menu in SwiftUI using the App protocol lifecycle? The storyboard/xib approach gives us a complete menu bar with even added menu items at run time which the system inserts and localizes for free such as "Enter Full Screen" and "Show/Hide Toolbar". The menu that SwiftUI gives us seems to be stripped down and not only does it not auto-localizes but there doesn't seem to be a way to localize it using strings file.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to "Recents" in document based app
The Recents item is just one of many items in the normal file picker, there's also iCloud Drive, On My iPad (or iPhone), Recently deleted etc. In order to get something in the Recents your app needs to have previously saved or read a document. If you run in the Simulator for the first time or erase the settings of the simulator device it would start with On My iPad (or iPhone) with a blank document icon which creates a new doc when the user taps on it. Concerning the spinning progress view, the system just tries to be smart by attempting to restore the previous state of the app by reopening the last viewed document, and if there aren't any, well it obviously can't. I haven't tried that on an actual connected device lately so I don't remember if it's just a Simulator oddity that the search never finishes.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20
Reply to How can I prevent a document-based swiftUI app from saving files?
I'm not on BigSur so I can't build your test app on my current machine, but you have declared your app as Editor for the role in you document type declaration: select your project in the navigator, select the target, go to Info tab, under Document Types set role to Viewer (which means your app does not create this type of doc) and try Handler rank to Alternate instead of Default (I think default is Owner if I remember correctly, which is not the case for your app). The type is also declared as Imported which is correct. Try that and see what difference it makes.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’20