i am making a macos app with a navigationview with a list in it and then navigation links. This works perfect and sets up a master/detail app just fine. What i cant get to work is a space between on the list (like on the catalina app store sidebar). I want 3 or 4 of the list items on the top and then 2 on the bottom. I tried using a spacer on the list but this just insterted one blank row. I also tried switching to a catalyst app but the spacer has the same effect there. How do i achieve this effect?
Post
Replies
Boosts
Views
Activity
so i made an entity in the xcdataodeld called Account with id,name attributes using the following code it would not compile giving errors that it cant find the Account entity. but when i create a second project for ios this code runs just fine (even in catalyst). But it will not work on a macos app. Im wondering is the code for accessing coredata different on mac then it is on ios? it should be the same espeically with swiftui.import SwiftUI
struct ContentView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(entity: Account.entity(), sortDescriptors: []) var account: FetchedResults
var body: some View {
Text("Hello, World!")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
the code below is a swiftui ios project with catalyst turned on. when i run this on the mac, and click on the accounts item in the first navigation view it loads the accounts view fine but there is a few lines of extra space above the header. how do i remove that space?import SwiftUI
struct ContentView: View {
init() {
UITableView.appearance().separatorStyle = .none
}
var body: some View {
NavigationView {
List {
NavigationLink("Accounts", destination: AccountsView())
NavigationLink("Budgets", destination: BudgetsView())
}
.navigationBarTitle("Sidebar")
.navigationBarHidden(true)
}
}
}
struct AccountsView: View {
@State var accounts: [Account] = [
Account(name: "Account #1"),
Account(name: "Account #2"),
Account(name: "Account #3"),
Account(name: "Account #4"),
]
var body: some View {
NavigationView {
List(accounts) { account in
NavigationLink(account.name, destination: Text(account.name))
}
.navigationBarTitle("Accounts")
}.background(Color(.purple))
}
}
struct BudgetsView: View {
var body: some View {
Text("Budgets")
}
}
struct Account: Identifiable {
var id: UUID = UUID()
var name: String
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
in this article from applethey post the following code, which they tout will give you a native sidebar look and feel. however when i add this code to my app delegate i get the error, "Use of unresolved identifier 'window'". I found a window variable in the scenedelage but not the appdelegate. did they change something after writting this article? If so how do i resolve this?func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let splitViewController = window!.rootViewController as! UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
// Add a translucent background to the primary view controller.
splitViewController.primaryBackgroundStyle = .sidebar
splitViewController.delegate = self
return true
}
I started building an app using catalyst, liking the idea of being able to use one code for all three apple devices. Problem is I can not have a simple dropdown on the catalyst app so I decided to split the app and use swiftui but for Mac and iOS so that I can have more Mac style controls like a dropdown.I spent all of last weekend figuring out how to get the tool bar working in catalyst and I finally was able to. So when I ported the app to Mac I go the following error in my toolbar func on the toolbar delegateUse of unresolved identifier 'UIBarButtonItem'I spent all night trying to figure out how to add this simple button to the toolbar and got nowhere. The segment control works fine but can't add a button. For now I am just using a segment control (since its working) with one button and text only.so how do I add a button (and use the system icons) to NSToolBar on a Mac swiftui app?func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
if (itemIdentifier == tbi1) {
let tbi = NSToolbarItemGroup(itemIdentifier: itemIdentifier, titles: ["Accounts","Budgets"], selectionMode: .selectOne, labels: ["One","Two"], target: self, action: #selector(tbi1_click))
tbi.selectedIndex = 0
return tbi
}
else if (itemIdentifier == tbi2) {
let bbi1 = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(tbi2_click))
let tbi = NSToolbarItem(itemIdentifier: itemIdentifier, barButtonItem: bbi1)
return tbi
}
return nil
}
I am trying to add a dropdown list in my SwiftUI catalyst app. from what I read you have to use the picker, but it does not let you use the popupbuttonpicker style on iOS. so how can I achieve a Mac style dropdown list in catalyst? I assume I have to basically roll my own out using views and popups?
the following code loads fine, the text and the double field both show 300. however when I click submit the text only changes to 0. you will see in the print output that the init was called with the new value of 0 but it does not update the double field? any suggestions?import SwiftUI
struct ContentView: View {
@State var amount:Double = 300
var body: some View {
VStack {
Text("\(self.amount)")
DoubleField(value: $amount)
Button(action: {self.amount=0}) {Text("Submit")}
}
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
struct DoubleField:View {
@Binding var doubleValue:Double
@State var stringValue:String
init(value: Binding) {
print("DoubleField.init(value: \(value.wrappedValue))")
self._doubleValue = value
self._stringValue = State(initialValue: "\(value.wrappedValue)")
}
var body: some View {
TextField("0.00", text: $stringValue)
}
}
I am getting the error, The file “21787.jpg” couldn’t be opened because you don’t have permission to view it.
how do I enable permissions to the app?
how do I make a new database from CloudKit dashboard?