Hi all, I've been struggling a bit with SwiftData, I have a really simple data model but I need to do a fairly complex query over a one-to-many relationship that results in aggregate values. And I want to be able to sort and filter those aggregates. The model looks like this: @Model class Category { var name: String var items = [Item]() } @Model class Item { var added: Date var checked: Date? } In a typical use case I'd expect their to be at most around 50 categories and perhaps 20 items per category. In my UI I would like to be able to sort categories in a couple of ways: by name, by date added and by date checked with a fallback on date added. Also, in my list view I want to be able to list categories and show the checked date of the most recently checked item. I can think of a couple of solutions here, to start of with I can do all the sorting and filtering client-side. In the list view I could retrieve all the categories and then find the most recently checked item per category and go from there. Another
Search results for
column
2,078 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
My MacOS app only cares about days, not time-of-days, so I made a simple Date Extension: extension Date { static func ==(lhs: Date, rhs: Date) -> Bool { let order = Calendar.current.compare(lhs, to: rhs, toGranularity: .day) return (order == .orderedSame) } } My app compiles fine and works as intended. However, #Preview is failing to build the preview, erroring with: CompileDylibError: Failed to build DayRow.swift Compiling failed: ambiguous use of operator '==' @__swiftmacro_45test_calendarview_PreviewReplacement_DayRow_133_EA4566EE578D744A3A6BCC599B1B43AALl0C0fMf_.swift ------------------------------ @available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, xrOS 1.0, *) struct $s45test_calendarview_PreviewReplacement_DayRow_133_EA4566EE578D744A3A6BCC599B1B43AALl0C0fMf_15PreviewRegistryfMu_: DeveloperToolsSupport.PreviewRegistry { static let fileID: String = test_calendarview_PreviewReplacement_DayRow_1/DayRow.1.preview-thunk.swift static let line: Int = 160 static let column: Int = 1 static func
Claude31, Exactly. In the application, the user will answer some questions and according to their answer, a certain column X row will be filled with information. Like this: The cell (col X row) to be filled depends on the user's response The content will be text, a string. You can restart the app at any time, when previously used cells must be cleaned.
Topic:
Programming Languages
SubTopic:
Swift
Tags:
Hello, I'm developing an app for Mac, Xcode 15.1, with Swift 5. I need to create a visual matrix, whose elements will be filled randomly, according to the choices the user makes. The matrix must have 10 columns and 40 rows. Does anyone know a component, or how to fill it dynamically and randomly? Thanks.
Hi there! Decided to post a reply, as I found a working solution. You can define custom grid items width and use it with LazyVGrid: struct MyView: View { let bulletListGridItems = [ GridItem(.fixed(10)), GridItem() ] var body: some View { LazyVGrid(columns: bulletListGridItems, alignment: .leading, content: { GridRow { VStack(alignment: .leading, content: { Text(•) Spacer() }) Text(Play the course as you find it and play the ball as it lies.) } } } This would return: Note, I'm using a Stack with Spacer() to push the bullet to the top of the grid row
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I have a table view where each row has two labels, one left-aligned and one right-aligned. I would like to reload a single row, but doing so causes the right-aligned label to hug the left-aligned label. Before the reload: After the reload: Reloading the whole table view instead, or disabling automatic row height, solves the issue. Can a single row be reloaded without resorting to these two workaround? class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { override func loadView() { let tableView = NSTableView() tableView.translatesAutoresizingMaskIntoConstraints = false tableView.dataSource = self tableView.delegate = self tableView.usesAutomaticRowHeights = true let column = NSTableColumn() column.width = 400 tableView.addTableColumn(column) let scrollView = NSScrollView(frame: CGRect(x: 0, y: 0, width: 500, height: 500)) scrollView.translatesAutoresizingMaskIntoConstraints = false scrollView.documentView = tableView view = scrollView Timer.scheduledTimer(withT
like Table(viewModel.rows, selection: $selection) { ForEach(viewModel.columns, id: .self) { column in TableColumn(column, value: { row in Text(row[column] as? String ?? ) }) } }
I have an iPhone 11 (MWJE2LL/A) for personal and development use. When I upgraded it to iOS 17.2.1 it stopped sync'ing to my computers. I can't sync or restore the iPhone. Both Finder and Music show the iPhone in the left column, but time out after 60 secs of Loading..., finally stating: The selected device could not be found. Xcode also does not see the connected iPhone, and does not list it in the available iOS build destinations. I have tried sync'ing using numerous Apple USB cables and computers (Mac Pro, 16 MacBook Pro, Mac Studio) all running macOS Sonoma 14.1. Is this a known bug in iOS 17.2? Is there a workaround so I can restore the iPhone and continue development work?
It looks like there's a new tab bar / column style design for tvOS that was introduced with the current TV app. Is there any word on this being a developer available component?
Hi all, I am new to Swift and I have found an issue which I can't fix. I use a TabView and if I change the views a few times, and go back to this view I get this error and I can't tab on any of the views any longer in the Navigation Stack. The way to fix it, is to force close the app and reopen it. Error message: A NavigationLink is presenting a value of type “NavigationItem” but there is no matching navigationDestination declaration visible from the location of the link. The link cannot be activated. Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView. Code: struct ToolsMainView: View { @State private var navigationPath = NavigationPath() var body: some View { NavigationStack(path: $navigationPath) { VStack { ScrollView(showsIndicators: false) { VStack { ForEach(navigationItems) { item in NavigationLink(value: item) { HStack(alignment: .center, spacing: 12) { Image(systemName: item.icon) Text(item.title) Spacer() Image(systemNa
Hi. I'm glad you asked this because I'm constantly tripping over SwiftUI syntax myself. There are a bunch of ways to express the contents of your NavigationSplitView. Note that SwiftUI is not Swift. It looks like Swift, it is written in Swift, but it is a domain specific language for creating descriptions of user interfaces. It extends the Swift language. If you look at the documentation for NavigationSplitView in Xcode's Documentation viewer, you'll find struct NavigationSplitView where Sidebar : View, Content : View, Detail: View and if you click on View, you'll find that it is a protocol. The initializer you are using is the one which creates a two-column view, with no control over the visibility of the columns public init(@ViewBuilder sidebar: () -> Sidebar, @ViewBuilder detail: () -> Detail) where Content == EmptyView The parameters (labelled sidebar and detail here) are closures - functions returning structs conforming to the View protocol. my SidebarView and DetailView are Views
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
HStack { ForEach(days, id:.self) { day in Text(day) .font(.system(size: 12, weight: .medium)) .frame(maxWidth: .infinity) } } LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 7), spacing: 20) { ForEach(fetchDates()) { value in ZStack { if value.day != -1 { let hasAppts = manager.days.contains(value.date.monthDayYearFormat()) NavigationLink(value: AppRouter.day(date: value.date)) { Text((value.day)) .foregroundColor(hasAppts ? .blue : .black) .fontWeight(hasAppts ? .bold : .none) .background { ZStack(alignment: .bottom) { Circle() .frame(width: 48, height: 48) .foregroundColor(hasAppts ? .blue.opacity(0.1) : .clear) if value.date.monthDayYearFormat() == Date().monthDayYearFormat() { Circle() .frame(width: 8, height: 8) .foregroundColor(hasAppts ? .blue : .gray) } } } } .disabled(!hasAppts) } else { Text() } } .frame(width: 32, height: 32) } } } .padding() }
I embedded a vertical scrollview to a calendar that was originally horizontally navigation with buttons. But its isn't scrolling changing months. What am I missing? let days = [SUN, MON, TUE, WED, THU, FRI, SAT] @State private var selectedMonth = 0 @State private var selectedDate = Date() @State private var path = NavigationPath() var body: some View { NavigationStack(path: $path) { ScrollView { VStack { Rectangle() .frame(height: 1) .foregroundColor(.gray) VStack(spacing: 20) { // Month Selection HStack { Spacer() Button { withAnimation { selectedMonth -= 1 } } label: { Image(systemName: lessthan.circle.fill) .resizable() .scaledToFit() .frame(width: 32, height: 32) .foregroundColor(.gray) } Spacer() Text(selectedDate.monthYearFormat()) .font(.title2) Spacer() Button { withAnimation { selectedMonth += 1 } } label: { Image(systemName: greaterthan.circle.fill) .resizable() .scaledToFit() .frame(width: 32, height: 32) .foregroundColor(.gray) } Spacer() } HStack { ForEach(days, id:.self) { day in Text(day) .font
I've finally initialized the DataFrame like this var trainingData: DataFrame = [keywords : data.trainingKeywords, target: data.trainingTargets] but now i'm getting this error when creating my data model like this: let model = try MLLinearRegressor(trainingData: trainingData, targetColumn: target) CreateML Type Error: Column keywords has element of unsupported type Any. Any idea from there on?
Topic:
Machine Learning & AI
SubTopic:
Core ML
Tags:
Hi, I've tried to find a solution for this problem for weeks now but it seems no one knows how to solve it and Apple doesn't seem to care. I have a NavigationSplitView with two columns. In the detail column I have a button - or any other clickable control - which is placed in the very top where usually the safe area resides. The button is NOT clickable when he is in the safe area and I have NO idea why. I know I can place buttons in safe areas of other views and they are clickable. Please have a look at the code: `struct NavTestView: View { var body: some View { GeometryReader { p in VStack(spacing: 0) { NavigationSplitView { List(names) { Text($0.name).frame(width: p.size.width) .background(Color.green) }.listRowSpacing(p.size.height * 0.15 / 100 ) .toolbar(.hidden, for: .navigationBar) } detail: { TestView().ignoresSafeArea() }.frame(width: p.size.width, height: p.size.height, alignment: .topLeading) .background(Color.yellow) } } } } struct TestView: View { var body: some View { GeometryRe