Posts

Post not yet marked as solved
2 Replies
294 Views
I tried to create an menubar application but since it contains multiple View in a Scroll, as you may imagine, i had to use .menuBarExtraStyle(.window). The point is: the first time I open the menu the height seems to layout properly, but from the second time on, the view resizes to a certain smaller height amount. You may try with this simple snippet: MenuBarExtra("", systemImage: "info") { ScrollView { VStack(alignment: .leading) { ForEach(0..<100) { Text("Row \($0)") } } } } .menuBarExtraStyle(.window) Changing .menuBarExtraStyle(.window) to .menuBarExtraStyle(.menu) fixes the problem but of course you can't build your own layout, functionalities, etc... just display. Even setting a maximum height - .frame(maxHeight: maxHeight) - for the ScrollView, doesn't seem to affect this behavior. Did anyone faced this issue? Maybe there's a proper way to proceed and build this kind of layout?
Posted
by matryx87.
Last updated
.
Post marked as solved
1 Replies
231 Views
I tried to create an menubar application but since it contains multiple View in a Scroll, as you may imagine, i had to use .menuBarExtraStyle(.window). The point is: the first time I open the menu the height seems to layout properly, but from the second time on, the view resizes to a certain smaller height amount. You may try with this simple snippet: MenuBarExtra("", systemImage: "info") { ScrollView { VStack(alignment: .leading) { ForEach(0..<100) { Text("Row \($0)") } } } } .menuBarExtraStyle(.window) Changing .menuBarExtraStyle(.window) to .menuBarExtraStyle(.menu) fixes the problem but of course you can't build your own layout, functionalities, etc... just display. Even setting a maximum height - .frame(maxHeight: maxHeight) - for the ScrollView, doesn't seem to affect this behavior. Did anyone faced this issue? Maybe there's a proper way to proceed and build this kind of layout?
Posted
by matryx87.
Last updated
.
Post not yet marked as solved
5 Replies
5.8k Views
Hi everyone!Here's a little tricky question, at least for me.I'm trying to add an apple watch extension to an existing app of mine (wrote in Swift).This App uses a CoreData database and i need to retrieve that data to build the Apple Watch UI.I decided to go for SwiftUI to code the Watch App, because of the new possibilities in the UI.So Main App in Swift and Watch App in SwiftUIFirst i created an app group of course, and a class to define a storeURL for the container:class AppGroupPersistentContainer: NSPersistentContainer { override open class func defaultDirectoryURL() -&gt; URL { var storeURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.ManhattanGroup") storeURL = storeURL?.appendingPathComponent("Manhattan.sqlite") return storeURL! } }in my core data manager (a class i created to crud) i placed the persistant container // MARK: - PersistentContainer lazy var persistentContainer: NSPersistentContainer = { let container = AppGroupPersistentContainer(name: "Manhattan") container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError("Unresolved error \(error), \(error.userInfo)") } }) return container }()then for each operation i just get the context from the persistent container. func getContext() -&gt; NSManagedObjectContext { return persistentContainer.viewContext }So far so good i guess.In my watch app, i call the context, and use that context for the environment.struct ContentView: View { var body: some View { let managedObjectContext = CoreDataManager.shared.getContext() return ZStack(alignment: .center) { CategoryView().environment(\.managedObjectContext, managedObjectContext) } } }finally in the CategoryView i fetch like this:@FetchRequest(entity: CoreList.entity(), sortDescriptors: []) var coreList: FetchedResults var body: some View { return VStack(alignment: .leading) { List { ForEach(coreList, id: \.self) { object in Text("\(object)") } }.environment(\.managedObjectContext, managedObjectContext)//not sure i should use this againand save like this:@Environment(\.managedObjectContext) var managedObjectContext var body: some View { return VStack(alignment: .leading) { ... Button("Add") { let coreList = CoreList(context: self.managedObjectContext) //coreList init try? self.managedObjectContext.save() }I can save and fetch locally successfully but this operations don't take effect on the iPhone App and as you can guess, if i save from the iPhone App i can't find these values on my Watch App.Does anyone have an idea? i think something is missing in the configuration of the app group but i just cant figure out.Thank you in advance.
Posted
by matryx87.
Last updated
.