Post

Replies

Boosts

Views

Activity

Reply to In SwiftUI I would like to declare an @ObservedObject var with a type defined in a protocol...
To declare an @ObservedObject var, you need a type conforming to ObservableObject. The protocol GalleryDataSource does inherit ObservableObject, but does not conform to ObservableObject. Currently, there is no way provided to make protocols to conform some other protocol in Swift. Better find another way. One possible alternative would be using generics: struct GalleryViewDataSource: GalleryDataSource: View { @ObservedObject var dataSource: DataSource var body: some View { ScrollView(.horizontal, content: { HStack { ForEach(0..self.dataSource.itemCount, id:\.self) { index in Text(dataSource.item(for: index)) .padding() } } }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Error loading Storyboard
How do I go about fixing the Mac environment in case it is broken which it most likely is?  Hard to say something sure. There may be many parts where Xcode would store intermediate something. But, for example, in my Mac using Xcode, there is no directory /Library/Caches/com.apple.xbs. You may need to find all such directories and try removing them. (Of course, you should better make backups before trying.)
May ’21
Reply to Error loading Storyboard
It is a different project, a new project that I created with no additions, I just created a new project, went straight to storyboard and bam, the issue was there already. I created a new project, opened the Main.storyboard with text editor and replaced the content with the XML you have shown. I then re-opened the project with Xcode 12.5, nothing happens. Opened Main.storyboard and Interface Builder opened without any problems. Ran the app, and the simulator started without any issues. I'm afraid your Mac environment might be broken. Have you upgraded your Mac from an older version? If so, there may be some remains of old Xcode tools or intermediate builds in your Mac.
May ’21
Reply to Data not passing correctly - SwiftUI, CoreData
Having multiple sheets controlled by a single @State variable is not recommended. Please try something like this: struct ItemsView: View { @Environment(\.managedObjectContext) private var viewContext @ObservedObject var group: ItemGroup @State private var showingDetailView = false @State var selectedItem: Item = Item() var body: some View { ScrollView { VStack(alignment: .leading) { ForEach(group.ongoingItems) { item in itemRow(for: item) .padding() } //... } //... } .sheet(isPresented: $showingDetailView, content: { ItemInfoSheet(item: $selectedItem) }) } func itemRow(for item: Item) - some View { HStack(spacing: 10) { //... Text(item.wrappedName) .fontWeight(.light) Spacer() Button(action: { selectedItem = item showingDetailView.toggle() }, label: { Image(systemName: "info.circle").imageScale(.large) }) } } //... } struct ItemInfoSheet: View { @Binding var item: Item var body: some View { NavigationView { ItemDetailView(selectedItem: item) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to SwiftUI NavigationLink isActive is not working right on iOS 14.5
this code should run well before iOS 14.5.  Can you clarify what you think is well? As far as I tried both with iOS 14.4 simulator of Xcode 12.4 and iOS 14.5 simulator of 12.5, your code behaves exactly the same: When you tap the link, the destination is shown. (And isActive gets true.) What do you expect for isActive? Aren't you confused with isActive and sort of disabled(_:)? Or am I misinterpreting what you mean? More than two NavigationLinks in List makes me very depressed. Can you show a complete code with enough description what you expect?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Protocol as return type
You mean, just treat it as a rule?  YES. It is not a description specific to this case, it is a general rule of protocol in Swift. The only exception I know is the protocol Error, which conforms to Error.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Windows iOS Development
Is it possible to make, test, and publish an iOS/iPadOS app on Windows 10? NO. Using some hybrid frameworks, you can make and test (in limited range) an iOS/iPadOS app on Windows, but you cannot publish it unless you can use a Mac. So is there any alternative/port of Xcode on Windows?  NO.
May ’21
Reply to Disable Dark Mode for iOS, iPadOS and macOS Catalyst App using Swift Programming Language
I have entered 'UIUserInterfaceStyle' as a key but it automatically replaced by 'Appearance'... It is not a problem, it actually is held as UIUserInterfaceStyle internally. If you want to see the raw key, choose Raw Keys & Values on the context menu shown in the editor of Info.plist. If you are sure you set Light there and it causes error on archiving, or it has no effect for LaunchScreen.storyboard, please share your experience.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21