Post

Replies

Boosts

Views

Activity

Swift UI TableColumn with Int data
I was playing around with TableColumn api in MacOS Ventura I have the following data model. actor HousingData: Identifiable {     let id: Int     let rank: Int     let region: String     let regionType: RegionType     let state: String } However when it try to do TableColumn("foo", value: \.rank) I get Key path value type 'Int' cannot be converted to contextual type 'String' if I try TableColumn("Rank", value: \.rank) { rank in Text("\(rank)") } I get Referencing initializer 'init(_:value:content:)' on 'TableColumn' requires the types 'Never' and 'KeyPathComparator<HousingData>' be equivalent If i use a string value all works well.
4
0
3.2k
Mar ’23
Dynamic TableColumns with ForEach
There seems to be no way to add dynamically add table columns to SwfitUI table. I have a column of dates that I store in an array like so. let dates = [Date] let values = [Int] I want one able enumerate over the dates to generate columns. However I can't seem to find a way to enumerate over them and generate my columns. My current data set has 250 columns and it will keep growing. I would love to do ForEach(0 ..< dates.length) { index in TableColumn("<some formatted date>") { Text("\(value)") } } But it appears that since TableColumn is not a view ForEach can't be used. Is there a supported way to build columns dynamically? This is a Mac application. Does charts support a for each type symantic too?
0
0
1.2k
Jun ’22
Regex code from WWDC sample code not working
If I past the samele code import RegexBuilder let fieldSeparator = /\s{2,}|\t/ let transactionMatcher = Regex { /CREDIT|DEBIT/ fieldSeparator One(.date(.numeric, locale: Locale(identifier: "en_US"), timeZone: .gmt)) fieldSeparator OneOrMore { NegativeLookahead { fieldSeparator } CharacterClass.any } fieldSeparator One(.localizedCurrency(code: "USD").locale(Locale(identifier: "en_US"))) } It does not like the OneOrMore with the negative look ahead. Is there an updated example of this code from WWDC?
1
1
1.3k
Jun ’22
LazyVStack child disappears off screen before its off screen.
I have a scroll view with one item in it. When is scroll it under a the navigation bar it disappears before the whole cell is gone it seems to be about when ½ the cell is disappeared. Simple LazyVStack   NavigationView {   ZStack {     ScrollView {       LazyVStack {             ForEach(model.wallets, id: \.id) { wallet in                 GalleryCell(wallet: wallet)               }       }        }   }
0
1
1.1k
Nov ’21
Full screen lazy stacks do not scroll on AppleTV.
I have a really simple app where I am trying to scroll full page between images. However the if I use a LazyHStack the scrolling stops working if a child item is full screen. LazyVStack has the same issue if the content is full screen then scrolling stops working. Normal stacks work but that defeats the purpose since all items have to load. Oh this need to scroll horizontally. Code is so: struct ContentView: View {     var body: some View {         GeometryReader { geometry in             ScrollView(.horizontal) {                 LazyHStack {                     ForEach(1...50, id: \.self) { index in                         Button(action: {}){ Text("\(index)")}                             .frame(width: geometry.size.width, height: geometry.size.height)                     }                 }             }         }         .ignoresSafeArea()     } }
3
0
2k
Nov ’21
Sign In with Apple Button on tvOS isn't working
I have a SwiftUI application with a SignInWithAppleButton. However when I press the button with the remote I don't get any callbacks in the blocks. There is no error in the console that I can find. Should the button work on tvOS 14? The code is simple: import SwiftUI import AuthenticationServices struct SignInView: View {     var body: some View {         VStack(spacing: 40) {             Text("Welcome to My App")                 .font(.system(size: 50.0, weight: .bold))             SignInWithAppleButton(.signIn) { request in                 request.requestedScopes = [.fullName, .email]             } onCompletion: { result in                 print(result)             }             .signInWithAppleButtonStyle(.whiteOutline)             .frame(width: 300, height: 50)         }     } }
3
1
1.2k
Sep ’21