Post

Replies

Boosts

Views

Activity

Accessing Existing Button with Tag?
I have a button (Click me) at the top. And it's followed by some space and stacks of buttons that are horizontally laid out as follows. import SwiftUI struct ContentView: View { 		var body: some View { 				ZStack { 						VStack(spacing: 0.0) { 								Button("Click me", action: { 																				 								}) 								Spacer() 										.frame(height: 20) 								 								HStack(spacing: 0.0) { 										ForEach((0...6), id: \.self) { 												Button("") { 														 												} 												.tag($0) 												.buttonStyle(BorderlessButtonStyle()) 												.frame(width: 48, height: 48, alignment: .center) 												.background(RoundedRectangle(cornerRadius: 2) 																				.fill(Color.white) 																				.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) 												) 										} 								} 								... 								... 								... 								HStack(spacing: 0.0) { 										ForEach((28...34), id: \.self) { 												Button("") { 														 												} 												.tag($0) 												.buttonStyle(BorderlessButtonStyle()) 												.frame(width: 48, height: 48, alignment: .center) 												.background(RoundedRectangle(cornerRadius: 2) 																				.fill(Color.white) 																				.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) 												) 										} 								} 								HStack(alignment: .top, spacing: 0.0) { 										ForEach((35...36), id: \.self) { 												Button("") { 														 												} 												.tag($0) 												.buttonStyle(BorderlessButtonStyle()) 												.frame(width: 48, height: 48, alignment: .center) 												.background(RoundedRectangle(cornerRadius: 2) 																				.fill(Color.white) 																				.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) 												) 										} 								} 								.frame(width: 336.0, height: 48.0, alignment: .leading) 						} 				} 		} } None of the buttons except the very top one has a title as you see above. And I want to set a title to each button and show or hide any of them when necessary. So is it possible for me to access any of the buttons with its tag and set its title and show or hide it? Thank you.
4
0
575
Dec ’20
Showing Selection with MenuButton
I want to create a drop-down menu with years like the following. import SwiftUI struct ContentView: View { 		@State var menuLabel = "2020" 		 		var body: some View { 				MenuButton(menuLabel) { 						Button("2020") { 								menuLabel = "2020" 						} 						Button("2021") { 								menuLabel = "2021" 						} 						Button("2022") { 								menuLabel = "2022" 						} 				} 				.frame(width: 68.0) 				.frame(maxWidth: .infinity, maxHeight: .infinity) 		} } But that's tedious. So if I would rather do it with ForEach. import SwiftUI struct ContentView: View { 		@State var menuLabel = "2020" 		 		var body: some View { 				MenuButton(menuLabel) { 						ForEach((2020...2030), id: \.self) { 								Button(String($0)) { 										menuLabel = String($0) 								} 						} 				} 				.frame(width: 68.0) 				.frame(maxWidth: .infinity, maxHeight: .infinity) 		} } And I will get an error unless I comment out menuLabel = String($0) It says Contextual closure type '() -> Void' expects 0 arguments, but 1 was used in closure body I don't know what it means. So what does it mean, and how can I set the selection to the title of MenuButton, anyway? Thank you.
2
0
2.2k
Dec ’20
Adding a Small Number to Each Button
Let me suppose that I have a horizontal stack of six buttons like the following. import SwiftUI struct ContentView: View { 		var body: some View { 				ZStack { 						VStack { 								HStack(spacing: 0.0) { 										Button("1") { 												 										} 										.buttonStyle(BorderlessButtonStyle()) 										.frame(width: 48, height: 48, alignment: .center) 										.background( 												RoundedRectangle(cornerRadius: 2) 														.fill(Color.white) 														.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) 										) 										... 										... 										... 										Button("6") { 												 										} 										.buttonStyle(BorderlessButtonStyle()) 										.frame(width: 48, height: 48, alignment: .center) 										.background( 												RoundedRectangle(cornerRadius: 2) 														.fill(Color.white) 														.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) 										) 								} 						} 				}.frame(minWidth: 360, idealWidth: 360, maxWidth: 360, minHeight: 240, idealHeight: 240, maxHeight: 240, alignment: .center) 		} } In the scenario above, each button is a size of 48 points x 48 points. And I want to add a small number at the top-left corner of each button. ('Small number' means a smaller font size than the button text size.) In Cocoa, it would be like adding (addSubView) an NSTextField object to an NSButton object. In SwiftUI, how can I add a small number to each button? Thank you.
4
0
469
Dec ’20
Calling a Function to Set Up Body
I have the following lines of code where I have several vertical stacks of horizontal stacks of buttons on top of a push button titled 'Click me.' import SwiftUI struct ContentView: View { &#9;&#9;@State private var eventPresented = false &#9;&#9;@State var fillColors: [Color] = Array(repeating: Color.white, count: 38) &#9;&#9;@State var buttonTitles: [String?] = Array(repeating: nil, count: 38) &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;/* click me */ &#9;&#9;&#9;&#9;&#9;&#9;VStack() { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button("Click me", action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;buttonTitles.removeAll() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;for i in 0..<38 { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;buttonTitles.append(String(i + 1)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;fillColors.removeAll() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;for _ in 0..<2 { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;fillColors.append(Color.clear) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;for _ in 0..<36 { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;fillColors.append(Color.white) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;/* cal buttons */ &#9;&#9;&#9;&#9;&#9;&#9;VStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((0...6), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[$0] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[$0]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(alignment: .top, spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((35...36), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[$0] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[$0]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 336.0, height: 48.0, alignment: .leading) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } If I click on 'Click me,' the application will label each button. My question is how I take the function out of this button. If I do something like the following as I used to doing in Cocoa and UIKit, I get an error. (I've created a function named 'makeButtons.') import SwiftUI struct ContentView: View { &#9;&#9;@State private var eventPresented = false &#9;&#9;@State var fillColors: [Color] = Array(repeating: Color.white, count: 38) &#9;&#9;@State var buttonTitles: [String?] = Array(repeating: nil, count: 38) &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;makeButtons() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;/* cal buttons */ &#9;&#9;&#9;&#9;VStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;HStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((0...6), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[$0] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[$0]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;HStack(alignment: .top, spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((35...36), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[$0] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[$0]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: Color.black.opacity(0.4), radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 336.0, height: 48.0, alignment: .leading) &#9;&#9;&#9;&#9;}.frame(minWidth: 370, idealWidth: 370, maxWidth: 370, minHeight: 420, idealHeight: 420, maxHeight: 420, alignment: .top) &#9;&#9;} &#9;&#9; &#9;&#9;func makeButtons() { &#9;&#9;&#9;&#9;buttonTitles.removeAll() &#9;&#9;&#9;&#9;for i in 0..<38 { &#9;&#9;&#9;&#9;&#9;&#9;buttonTitles.append(String(i + 1)) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;fillColors.removeAll() &#9;&#9;&#9;&#9;for _ in 0..<2 { &#9;&#9;&#9;&#9;&#9;&#9;fillColors.append(Color.clear) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;for _ in 0..<36 { &#9;&#9;&#9;&#9;&#9;&#9;fillColors.append(Color.white) &#9;&#9;&#9;&#9;} &#9;&#9;} } Thank you.
5
0
676
Dec ’20
MenuButton Title Dimmed Out
I have two MenuButtons, equivalent to NSPopupButtons in Cocoa. One has a list of years, starting at 2020, and the other lists calendar months. So I have the following test code to see how the MenuButton button works. import SwiftUI struct ContentView: View { &#9;&#9;@State var yearSelection = 2020 &#9;&#9;@State var monthSelection = 12 &#9;&#9;@State var monthLiteral = "December" &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;ZStack { &#9;&#9;&#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Spacer() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(height: 8) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Spacer() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 16) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;MenuButton(String(yearSelection)) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((2020...2030), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;year in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(String(year)) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;yearSelection = year &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}.frame(width: 68.0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;MenuButton(monthLiteral) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((1...12), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;month in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;let monStr = Calendar.current.monthSymbols[month - 1] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(monStr) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;monthSelection = month &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;monthLiteral = monStr &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}.frame(width: 102.0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Spacer() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Spacer() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button("Select me") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;yearSelection = 2024 &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;}.frame(minWidth: 370, idealWidth: 370, maxWidth: 370, minHeight: 200, idealHeight: 200, maxHeight: 200, alignment: .center) &#9;&#9;} } Initially being black, if I use the year menu button to select a year, its title color will turn light gray. If I touch the menu button with the mouse pointer, the title color will turn back black. If I click on the select me push button at the bottom to select a year, again, the title color will turn light gray. Is that how the menu button works? It's kind of a cheap Dutch doll. (No offense to Dutch people...). I think this stack overflow topic - https://stackoverflow.com/questions/65050365/issue-about-menu-title-under-macos-decreased-opacity is what I'm talking about. Or am I doing something wrong? Thank you.
0
0
305
Dec ’20
Passing a Value ($0) to the State Var
I have several vertical stacks of six horizontal buttons. And I want to open a modal sheet based on the button they click on. import SwiftUI struct ContentView: View { &#9;&#9;@State private var eventPresented = false &#9;&#9;@State private var selectedEventIndex = 3 &#9;&#9; &#9;&#9;@State var shadowColors: [Color] = Array(repeating: Color.clear, count: 38) &#9;&#9;@State var titleColors: [Color] = Array(repeating: Color.black, count: 38) &#9;&#9;@State var fillColors: [Color] = Array(repeating: Color.clear, count: 38) &#9;&#9;@State var buttonTitles: [String?] = Array(repeating: nil, count: 38) &#9;&#9;@State var eventNumbers: [String?] = Array(repeating: nil, count: 38) &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;VStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((0...6), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[$0] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedEventIndex = 5 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(titleColors[$0]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.overlay(Text(eventNumbers[$0] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[$0]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: shadowColors[$0], radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $eventPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;EventView(eventVisible: self.$eventPresented, valueFromParent: self.$selectedEventIndex) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(alignment: .top, spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((35...36), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[$0] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedEventIndex = 5 &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(titleColors[$0]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.overlay(Text(eventNumbers[$0] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[$0]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: shadowColors[$0], radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $eventPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;EventView(eventVisible: self.$eventPresented, valueFromParent: self.$selectedEventIndex) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 336.0, height: 48.0, alignment: .leading) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } struct EventView: View { &#9;&#9;@Binding var eventVisible: Bool &#9;&#9;@Binding var valueFromParent : Int &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;Text("This is a sheet.") &#9;&#9;&#9;&#9;&#9;&#9;Button("OK") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.eventVisible = false &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("From parent: \(valueFromParent)") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.frame(width: 240, height: 180) &#9;&#9;} } For now, I arbitrarily set eventPresented to 5, which will be passed to EventView. How can I set $0 to this state value like eventPresented = $0 Thank you.
2
0
836
Dec ’20
Too Complex To Check Code in Reasonable Time?
Again, I have a vertical stack of horizontal stacks of buttons as follows. import SwiftUI struct ContentView: View { &#9;&#9;@State private var eventPresented = Bool() &#9;&#9;@State private var selectedEventIndex = Int() &#9;&#9;@State private var monthSelection = Int() &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;VStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((0...6), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;index in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[index] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedEventIndex = index + 1 - self.weekIndex &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(titleColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $eventPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex, monthFromParent: self.$monthSelection) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;... &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(alignment: .top, spacing: 0.0) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ForEach((35...36), id: \.self) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;index in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(buttonTitles[index] ?? "") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;eventPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;selectedEventIndex = index + 1 - self.weekIndex &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(titleColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.buttonStyle(BorderlessButtonStyle()) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 48, height: 48, alignment: .center) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(RoundedRectangle(cornerRadius: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fill(fillColors[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $eventPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex, monthFromParent: self.$monthSelection) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 336.0, height: 48.0, alignment: .leading) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } And I want to send a few variables to EventView when the user clicks on a button. struct EventView: View { &#9;&#9;@Binding var eventVisible: Bool &#9;&#9;@Binding var dayFromParent: Int &#9;&#9;@Binding var monthFromParent: Int &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;Text("Window sheet.") &#9;&#9;&#9;&#9;&#9;&#9;Button("OK") { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.eventVisible = false &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("month from parent: \(monthFromParent)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("day from parent: \(dayFromParent)") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.frame(width: 240, height: 180) &#9;&#9;} } If I just want to send two variables to it, EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex) the compiler didn't complain. For the third variable, it says SwiftUI the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions I know what it means. Some say it could resolve the issue by making the data types of variables clearer. Others say you could use a function to return a variable for a somewhat complex algebra equation. But what can I do in my case? Does anybody have any suggestions? Thank you
6
0
701
Dec ’20
Opening an NSViewController as a Sheet
I have a SwiftUI view with a button. I want to open a window sheet from a storyboard. Showing a window sheet isn't a problem. It's just that the application no longer has a menu bar. As soon as I created a storyboard and a view controller (NSViewController), the application stopped showing up properly. Now, if I try to debug it (Command + R), the window won't appear. So I have to click on the Live Preview button on the Canvas. If I do, I can click on the Bring Forward button. Finally, if I click on it, the application window always appears at the bottom-left corner of the desktop without the menu bar. So what's the issue? Anyway, the following is my code. // SwiftUI View // import SwiftUI struct ContentView: View { &#9;&#9;@State private var sheetPresented = false &#9;&#9;@State private var selectionIndex = 3 &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;ZStack { &#9;&#9;&#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;sheetPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Show me a sheet") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $sheetPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;SheetViewControllerRepresentation(message: String(selectionIndex)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;}.frame(minWidth: 360, idealWidth: 360, maxWidth: 360, minHeight: 240, idealHeight: 240, maxHeight: 240, alignment: .center) &#9;&#9;} } // View controller // import Cocoa import SwiftUI class SheetViewController: NSViewController { &#9;&#9;// MARK: - &#9;&#9;var message = String() &#9;&#9; &#9;&#9; &#9;&#9;// MARK: - IBOutlet &#9;&#9;@IBOutlet weak var messageLabel: NSTextField! &#9;&#9; &#9;&#9; &#9;&#9;// MARK: - Life cycle &#9;&#9;override func viewDidLoad() { &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;&#9;&#9;// Do view setup here. &#9;&#9;} &#9;&#9; &#9;&#9;override func viewWillAppear() { &#9;&#9;&#9;&#9;super.viewWillAppear() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;messageLabel.stringValue = message &#9;&#9;} &#9;&#9; &#9;&#9;override func viewDidAppear() { &#9;&#9;&#9;&#9;super.viewDidAppear() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;view.setFrameSize(CGSize(width: 320, height: 220)) &#9;&#9;} } struct SheetViewControllerRepresentation: NSViewControllerRepresentable { &#9;&#9;var message = String() &#9;&#9; &#9;&#9;func makeNSViewController(context: NSViewControllerRepresentableContext<SheetViewControllerRepresentation>) -> SheetViewController { &#9;&#9;&#9;&#9;let mainStoryboard = NSStoryboard(name: "Main", bundle: nil) &#9;&#9;&#9;&#9;let sheetViewController = mainStoryboard.instantiateController(withIdentifier: "SheetView") as! SheetViewController &#9;&#9;&#9;&#9;sheetViewController.message = self.message &#9;&#9;&#9;&#9;return sheetViewController &#9;&#9;} &#9;&#9; &#9;&#9;func updateNSViewController(_ nsViewController: SheetViewController, context: NSViewControllerRepresentableContext<SheetViewControllerRepresentation>) { &#9;&#9;} } Thank you.
1
0
353
Dec ’20
Opening an NSViewController as a Sheet
I have a SwiftUI desktop application. And I need to open a window sheet from a storyboard with a click of a button, which works. But I have a problem. The opening window sheet is very big. Its size is 1,400 x 300 pixels. (I don't know the exact height.) I don't know where this size comes from. But I need to make it smaller. If I try to do it with the view controller, it doesn't work. How can I control the opening window sheet size? // SwiftUI View // import SwiftUI struct ContentView: View { &#9;&#9;@State private var sheetPresented = false &#9;&#9;@State private var selectionIndex = 3 &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;ZStack { &#9;&#9;&#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;sheetPresented = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Show me a sheet") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.sheet(isPresented: $sheetPresented) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;SheetViewControllerRepresentation(message: String(selectionIndex)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;}.frame(minWidth: 360, idealWidth: 360, maxWidth: 360, minHeight: 240, idealHeight: 240, maxHeight: 240, alignment: .center) &#9;&#9;} } // View controller // import Cocoa import SwiftUI class SheetViewController: NSViewController { &#9;&#9;// MARK: - &#9;&#9;var message = String() &#9;&#9;&#9;&#9; &#9;&#9;// MARK: - IBOutlet &#9;&#9;@IBOutlet weak var messageLabel: NSTextField! &#9;&#9;// MARK: - IBAction&#9;&#9; &#9;&#9;@IBAction func closeClicked(_ sender: NSButton) { &#9;&#9;&#9;&#9;/* closing window */ &#9;&#9;&#9;&#9;self.view.window?.setIsVisible(false) &#9;&#9;&#9;&#9;self.view.window?.close() &#9;&#9;} &#9;&#9;// MARK: - Life cycle &#9;&#9;override func viewDidLoad() { &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;&#9;&#9;// Do view setup here. &#9;&#9;} &#9;&#9; &#9;&#9;override func viewWillAppear() { &#9;&#9;&#9;&#9;super.viewWillAppear() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;messageLabel.stringValue = message &#9;&#9;} &#9;&#9; &#9;&#9;override func viewDidAppear() { &#9;&#9;&#9;&#9;super.viewDidAppear() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;view.setFrameSize(CGSize(width: 320, height: 220)) &#9;&#9;} } struct SheetViewControllerRepresentation: NSViewControllerRepresentable { &#9;&#9;var message = String() &#9;&#9; &#9;&#9;func makeNSViewController(context: NSViewControllerRepresentableContext<SheetViewControllerRepresentation>) -> SheetViewController { &#9;&#9;&#9;&#9;let mainStoryboard = NSStoryboard(name: "Main", bundle: nil) &#9;&#9;&#9;&#9;let sheetViewController = mainStoryboard.instantiateController(withIdentifier: "SheetView") as! SheetViewController &#9;&#9;&#9;&#9;sheetViewController.message = self.message &#9;&#9;&#9;&#9;return sheetViewController &#9;&#9;} &#9;&#9; &#9;&#9;func updateNSViewController(_ nsViewController: SheetViewController, context: NSViewControllerRepresentableContext<SheetViewControllerRepresentation>) { &#9;&#9;} } Thank you.
4
0
1k
Dec ’20
Project deployment target and Cocoapod target version
Let me suppose that I have an Xcode project that uses the following Cocoapods. &#9;pod 'Firebase/Auth' &#9;pod 'GoogleSignIn' And let me also suppose that the minimum deployment target for my Xcode project is 11.0. In this case, do I set the Cocoapod platform to 11.0 like platform :ios, '11.0' target 'MyProject' do &#9;use_frameworks! &#9;pod 'Firebase/Auth' &#9;pod 'GoogleSignIn' end Or do I use the latest versions of Cocoapods like platform :ios, '14.2' target 'MyProject' do &#9;use_frameworks! &#9;pod 'Firebase/Auth' &#9;pod 'GoogleSignIn' end ? Thanks.
1
0
3.2k
Jan ’21
Developing an App for a Third Party
When you develop an iOS app for some company, say Company A, under whose name should you sign up a developer account so that you can code-sign the app and send it to the iTunes Connect server? Is it you or Company A? I am thinking that I can sign up a new account to submit an app as long as I give the copyright to Company A. My concern is that there was a new rule like Spamming that took effect several years ago. I guess some guys were using the same package and only changed superficial aspects to submit a ton of similar apps. Thanks. p.s. It's not an in-house app under an enterprise account that I'm talking about. The app will be submitted to the App Store.
1
0
499
Jan ’21
Using TestFlight Before Submission?
Hello. I'm a little bit confused about how TestFlight works. If I have an iOS app under development that has not been in the store and that has not been submitted for a review yet, can I use TestFlight to have it tested by my development team? I know that there are two types of tests, internal tests and external tests. It seems that you can use TestFlight for internal tests even if the app has not been submitted for a review. Thanks.
1
0
648
Jan ’21
Value of type 'UIView?' has no member 'isEnabled'
I have the following lines of code in practicing Combine. import UIKit import Combine class ViewController: UIViewController { // MARK: - Variables var cancellable: AnyCancellable? @Published var segmentNumber: Int = 0 // MARK: - IBOutlet @IBOutlet weak var actionButton: UIButton! // MARK: - IBAction @IBAction func segmentChanged(_ sender: UISegmentedControl) { segmentNumber = sender.selectedSegmentIndex } // MARK: - Life cycle override func viewDidLoad() { super.viewDidLoad() cancellable = $segmentNumber.receive(on: DispatchQueue.main) .assign(to: \.isEnabled, on: actionButton) } } I get an error at .assign that says Value of type 'UIView?' has no member 'isEnabled' What am I doing wrong? Thank you.
3
0
2.3k
Aug ’21
Practical Use of Combine's Subject
I'm trying to understand how Combine works. The following is my sample code. import UIKit import Combine class ViewController: UIViewController { // MARK: - Variables var cancellable: AnyCancellable? // MARK: - IBAction @IBAction func buttonTapped(_ sender: UIButton) { currentValueSubject.send(20) } // MARK: - Life cycle var currentValueSubject = CurrentValueSubject<Int, Never>(1) override func viewDidLoad() { super.viewDidLoad() let cancellable = currentValueSubject .sink { value in print("New value: \(value)") } currentValueSubject.send(5) currentValueSubject.send(10) //currentValueSubject.send(completion: .finished) currentValueSubject.send(15) //cancellable.cancel() } } If I run it with the iPhone simulator, I get New value: 1 New value: 5 New value: 10 New value: 15 If I tap the button, the app won't get a new value. I suppose that's because the subscription is cancelled at the end of viewDidLoad? If so, why does it get cancelled? I don't quite see a practical side of Combine's Subject. When is it useful? Thanks.
2
0
1.1k
Aug ’21
Navigation title with LayoutConstraints Warnings in Console
I just want to show a simple navigation title like the following. import SwiftUI struct ContentView: View { var body: some View { NavigationView { ZStack { Color.red.edgesIgnoringSafeArea(.all) Text("Hello") } .navigationTitle("GGG") .navigationBarTitleDisplayMode(.inline) .navigationBarHidden(false) } } } And I get a bunch of mumbo jumbo auto-layout warnings (Unable to simultaneously satisfy constraints...) in Console. If I comment out the navigationTitle line, I won't get them. I have never seen those messages in showing a navigation title when writing code with UIKit. What am I doing wrong? Muchos thankos
1
0
517
Sep ’21