Post

Replies

Boosts

Views

Activity

XCode 13 Reference
Is there a good tutorial and reference (preferably a book) for XCode 13? I'm looking for something of the caliber of the Swift manual. The Swift manual was free for the download, but I am willing to pay for a good XCode book. I'm looking for more than the built in help. Thanks, Mark
1
0
400
Oct ’21
Xcode 13 hides Products folder in Project Navigator
Apple recently automatically upgraded me from Xcode 12 to Xcode 13. I've been building command line utilities. In Xcode 12, the output of the build showed up in the Project Navigator. I could drag that to an open terminal window and it would enter the full, convoluted, path to my executable ready to add command line parameters and run. Now in Xcode 13, I don't see the build target in the Project Navigator. Is there an easy way to put the path in the terminal window? I see in the release notes, where hiding the Products folder when it is in the default location is a now a "feature" in Xcode 13. While there is the "Show in Finder" option under the Product menu, that's not as easy as before. Is there a way to unhide the Products folder, even if it is in the default location? I suppose I could change the default location, but then I'd have to do it on every new project.
0
0
873
Sep ’21
Array of @State (or a better way)
I'm just learning Swift and SwiftUI. I'm trying to write a segmented level indicator. Each segment is a separate view (RoundedRectangle) that draws itself with a 0.1 opacity for off or a 1.0 opacity for on. It draws in green, yellow or red depending on the level. I haven't been able to figure out a way to create an array of @State variables, so there is a lot of otherwise redundant code struct ContentView: View {     @State private var value = 0.0              @State private var segment0 = false     @State private var segment1 = false     @State private var segment2 = false     @State private var segment3 = false     @State private var segment4 = false     @State private var segment5 = false     @State private var segment6 = false     @State private var segment7 = false     @State private var segment8 = false     @State private var segment9 = false     var body: some View {         let valueBinding = Binding(             get: {return self.value},             set: {                 self.value = $0                 let intValue = Int(self.value)                 for i in 0...9 {                     let isOn = intValue > i                     switch (i) {                     case 0:                         if isOn != segment0 {segment0 = isOn}                     case 1:                         if isOn != segment1 {segment1 = isOn}                     case 2:                         if isOn != segment2 {segment2 = isOn}                     case 3:                         if isOn != segment3 {segment3 = isOn}                     case 4:                         if isOn != segment4 {segment4 = isOn}                     case 5:                         if isOn != segment5 {segment5 = isOn}                     case 6:                         if isOn != segment6 {segment6 = isOn}                     case 7:                         if isOn != segment7 {segment7 = isOn}                     case 8:                         if isOn != segment8 {segment8 = isOn}                     case 9:                         if isOn != segment9 {segment9 = isOn}                     default:                         break                     }                 }             }         )                  VStack {             HStack(                 alignment: .top,                 spacing: 1             ) {                 CellView(isOn: $segment0, color:Color.green)                 CellView(isOn: $segment1, color:Color.green)                 CellView(isOn: $segment2, color:Color.green)                 CellView(isOn: $segment3, color:Color.green)                 CellView(isOn: $segment4, color:Color.green)                 CellView(isOn: $segment5, color:Color.yellow)                 CellView(isOn: $segment6, color:Color.yellow)                 CellView(isOn: $segment7, color:Color.yellow)                 CellView(isOn: $segment8, color:Color.red)                 CellView(isOn: $segment9, color:Color.red)             }             SliderView(value: valueBinding)         }         .padding()              } } struct SliderView: View {     @Binding var value: Double     var body: some View {         Slider(value: $value, in: 0...10)             .frame(width: 200)     } }      struct CellView: View {     @Binding var isOn: Bool     let color: Color     let cornerSize: CGFloat = 4     let size:CGFloat = 20          var body: some View {         print ("cell")         return RoundedRectangle(cornerSize: CGSize(width: cornerSize, height: cornerSize))             .opacity(isOn ? 1.0 : 0.1)             .foregroundColor(color)             .frame(width:size, height:size)     } } My first attempt bound the value Double (directly from the Slider) to all of the RoundedRectangle views and each view determined whether is was on or off, and it worked, but SwiftUI redrew all the RoundedRectangle views each time value changed and that seemed inefficient. This way, only the views that actually need to change are redrawn. Any ideas? Thanks, Mark
0
0
395
Sep ’21