Post

Replies

Boosts

Views

Activity

@FetchRequest doesn't respect fetchBatchSize
Hello, I am building a list in SwiftUI, using the @FetchRequest property wrapper to fetch core data entities, taking as input a fetch request which has the property fetchBatchSize set to 50. import SwiftUI import CoreData extension Item { static var listRequest: NSFetchRequest<Item> { let request = Item.fetchRequest() request.fetchBatchSize = 50 request.sortDescriptors = [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)] return request } } struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @FetchRequest(fetchRequest: Item.listRequest) private var items: FetchedResults<Item> var body: some View { NavigationView { List { ForEach(items) { item in Text(item.timestamp!, formatter: itemFormatter) } } } } } But when loading my list with 3000 items and having the argument -com.apple.CoreData.SQLDebug enabled, there are 241 calls made to load my items 50 by 50 at a time. There is no mention of fetchBatchSize in the documentation, but this feature of fetch request is really important to me when building App dealing with large datasets of objects. Am I doing something wrong or is there any recommandation about large data sets performances with SwiftUI lists indicating the best practices? Thanks for your help !
0
1
304
Aug ’23
Multiline label with UIViewRepresentable
Hello, I'm trying to use a component created with UIKit in SwiftUI by using UIViewRepresentable. The result I want to achieve is to have a textfield on top of my view and my UIKit view stacked at the bottom with an automatic height. The problem is this component includes a multiline label and from what I see it makes it really hard to have an automatic height working properly, so my UIKit component takes all the available space in my VStack. On the left, the actual result. On the right, the expected result. Here is my code included in a playground to test it. I tried to play with hugging priorities but nothing worked for me, and if I test with a swift UI view it works correctly.. Any ideas? import UIKit import Foundation import SwiftUI import PlaygroundSupport class InformationView: UIView { lazy var label = UILabel() lazy var button = UIButton(type: .custom) override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .red addSubview(label) addSubview(button) label.text = "zaeiof azoeinf aozienf oaizenf oazeinf oaziefj oazeijf oaziejf aozijf oaizje foazeafjoj" label.numberOfLines = 0 label.setContentHuggingPriority(.required, for: .vertical) label.translatesAutoresizingMaskIntoConstraints = false button.translatesAutoresizingMaskIntoConstraints = false button.setTitle("My button title", for: .normal) button.setContentCompressionResistancePriority(.required, for: .horizontal) addConstraints([ label.leadingAnchor.constraint(equalTo: leadingAnchor), label.topAnchor.constraint(equalTo: topAnchor), label.bottomAnchor.constraint(equalTo: bottomAnchor), label.trailingAnchor.constraint(equalTo: button.leadingAnchor, constant: -10), button.trailingAnchor.constraint(equalTo: trailingAnchor), button.centerYAnchor.constraint(equalTo: centerYAnchor) ]) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } struct InformationRepresenter: UIViewRepresentable { func makeUIView(context: Context) -> InformationView { let view = InformationView(frame: .zero) view.setContentHuggingPriority(.required, for: .vertical) return view } func updateUIView(_ uiView: InformationView, context: Context) { } } struct Info: View { var body: some View { return HStack { Text("zaeiof azoeinf aozienf oaizenf oazeinf oaziefj oazeijf oaziejf aozijf oaizje foazeafjoj") Button("My button title", action: { print("test") }) } } } struct ContentView: View { @State var text = "" var body: some View { VStack { TextField("Field", text: $text) .padding() Spacer() // SwiftUI works // Info().background(Color.red).padding() // UIViewRepresentable doesn't InformationRepresenter().padding() } } } PlaygroundPage.current.setLiveView(ContentView().frame(width: 400, height: 800, alignment: .top))
1
0
1.4k
Jun ’21
Can’t archive App that uses a swift package with an xcframework
Hello, We have a situation where: we have a library A distributed as an xcframework. this library A is used in a swift package B that includes it as a binary target. our final iOS App uses our swift package B with swift package manager. We first had issues with code signing and solved it by adding a build phase that code sign the framework A when building the App. Now everything is fine when running in debug but when trying to archive the App, We have a compilation error saying Xcode doesn’t find the framework A.. we try a lots of different setup but didn’t find any solution to fix this compilation error. Any idea on how we could solve this issue? Thanks!
18
0
10k
Sep ’20