Post

Replies

Boosts

Views

Activity

Reply to How to write AVAudioBuffer to a file?
How should plain AVAudioBuffer be handled? AVAudioBuffer is sort of an abstract super type of AVAudioPCMBuffer. You can check its type and cast it to AVAudioPCMBuffer. And as far as I tried, writeUtterance:toBufferCallback: always uses AVAudioPCMBuffer as buffer. You may need to abandon further processing if it was not.
Topic: Media Technologies SubTopic: Audio Tags:
Sep ’21
Reply to Calling a View
It depends on many things, but one possible way is to use sheet or fullScreenCover: struct ContentView: View { @State var search: String = "abc" @State var isPresented: Bool = false var body: some View { VStack { Button(action: { self.isPresented = true }) { Text("Search") } } .fullScreenCover(isPresented: $isPresented, content: { MyViewB(keyword: self.search) }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to How to save the state of a Switch
OK so I rewrote some code, Thanks, that makes sense a little more than the original code. But still, a few things: Having UI elements as data would not be a good practice You use textLabel although you define settingLabel in your custom cell You may need to reflect the state of each switch to some sort of data source. Please try something like this. Prepare a custom cell which can reflect the changes of switch: class SettingsCustomCell: UITableViewCell { @IBOutlet weak var settingLabel: UILabel! @IBOutlet weak var quickAddSwitch: UISwitch! var state: SettingsState? { didSet { if let state = state { settingLabel.text = state.settingLabel quickAddSwitch.isOn = state.settingValue } } } override func awakeFromNib() { quickAddSwitch.addTarget(self, action: #selector(switchValueChanged), for: .valueChanged) } @objc func switchValueChanged(sender: UISwitch) { state?.settingValue = sender.isOn } } class SettingsState { var settingLabel: String var settingValue: Bool init(settingLabel: String, settingValue: Bool) { self.settingLabel = settingLabel self.settingValue = settingValue } } And use it like this: class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource { var cellStates: [SettingsState] = [ SettingsState(settingLabel: "Quick Add", settingValue: false), ] func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return cellStates.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = table.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SettingsCustomCell cell.state = cellStates[indexPath.row] return cell } @IBOutlet weak var table: UITableView! override func viewDidLoad() { super.viewDidLoad() table.dataSource = self // Load `cellStates` if you need it... // (I could not find when you want to save it.) } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to List Sections
Thanks for showing the code. I could have reproduce the similar layout with the new code. (I used simplified layout because I could not make it work but that was enough. By the way, you should better follow the naming rule of Swift when you write code in Swift.) With this part: List(data) { data in Section(header: Text("GroupPicks")) { layout(data: data) } } You are trying to add a section to each row of your List. Which causes the result as shown in your previous screen shot. Putting Section inside List(data) { ... } does not make sense. Please try something like this: if data.count == 0 { Text("No Picks Found") } else { List { Section(header: Text("GroupPicks")) { ForEach(data) { data in layout(data: data) } } } .listStyle(GroupedListStyle()) //.listStyle(PlainListStyle()) //.listStyle(InsetListStyle()) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Array Elements - Getting Control
Unfortunately, the forums lack very important feature -- editing old posts. You may need to use Your Answer to show additional info. In addition, please show the complete definition of your Data. (Generally, you should better not use the same type name as very popular standard type names.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to How to save the state of a Switch
I want to save the state when there is a change to the switch state Please modify the code above as follows: class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource { //... override func viewDidLoad() { super.viewDidLoad() table.dataSource = self // Load `cellStates` if you need it... NotificationCenter.default.addObserver(self, selector: #selector(switchDidChange), name: .switchDidChange, object: nil) } @objc func switchDidChange(_ notification: Notification) { // Save `cellStates`... } } class SettingsCustomCell: UITableViewCell { //... @objc func switchValueChanged(sender: UISwitch) { state?.settingValue = sender.isOn NotificationCenter.default.post(name: .switchDidChange, object: self) } } extension Notification.Name { static let switchDidChange = Notification.Name("switchDidChange") }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to I am creating a meditation app. I want to repeat the time to inhale and the time to exhale.
You should better respond to answers of another question of yours.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to save the state of a Switch
You declare Settings_Custom_Cell (a very odd name as Swift code), but you are not using it in Settings. Have you really set up the storyboard for Settings to use the custom class Settings_Custom_Cell for the reuse identifier cell?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Create ios Swift Framework independent of Xcode Compiler Version
Have you tried setting BUILD_LIBRARY_FOR_DISTRIBUTION? Library Evolution in Swift
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Official reference for "#available" in Swift language?
Can anybody tell me whether there is official reference? I would not say the official documentation of Swift (so called the Swift book) is easy to read, but there actually is. Availability Condition It is classified into Statements of the doc, maybe because it is only used inside conditional statements.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to write AVAudioBuffer to a file?
How should plain AVAudioBuffer be handled? AVAudioBuffer is sort of an abstract super type of AVAudioPCMBuffer. You can check its type and cast it to AVAudioPCMBuffer. And as far as I tried, writeUtterance:toBufferCallback: always uses AVAudioPCMBuffer as buffer. You may need to abandon further processing if it was not.
Topic: Media Technologies SubTopic: Audio Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Calling a View
It depends on many things, but one possible way is to use sheet or fullScreenCover: struct ContentView: View { @State var search: String = "abc" @State var isPresented: Bool = false var body: some View { VStack { Button(action: { self.isPresented = true }) { Text("Search") } } .fullScreenCover(isPresented: $isPresented, content: { MyViewB(keyword: self.search) }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Axie test flight
NO. At least not here.
Replies
Boosts
Views
Activity
Sep ’21
Reply to Array Elements - Getting Control
Can you clarify what you want to ask?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to save the state of a Switch
OK, then can you explain why you are not using Settings_Custom_Cell in your code?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to save the state of a Switch
OK so I rewrote some code, Thanks, that makes sense a little more than the original code. But still, a few things: Having UI elements as data would not be a good practice You use textLabel although you define settingLabel in your custom cell You may need to reflect the state of each switch to some sort of data source. Please try something like this. Prepare a custom cell which can reflect the changes of switch: class SettingsCustomCell: UITableViewCell { @IBOutlet weak var settingLabel: UILabel! @IBOutlet weak var quickAddSwitch: UISwitch! var state: SettingsState? { didSet { if let state = state { settingLabel.text = state.settingLabel quickAddSwitch.isOn = state.settingValue } } } override func awakeFromNib() { quickAddSwitch.addTarget(self, action: #selector(switchValueChanged), for: .valueChanged) } @objc func switchValueChanged(sender: UISwitch) { state?.settingValue = sender.isOn } } class SettingsState { var settingLabel: String var settingValue: Bool init(settingLabel: String, settingValue: Bool) { self.settingLabel = settingLabel self.settingValue = settingValue } } And use it like this: class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource { var cellStates: [SettingsState] = [ SettingsState(settingLabel: "Quick Add", settingValue: false), ] func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return cellStates.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = table.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SettingsCustomCell cell.state = cellStates[indexPath.row] return cell } @IBOutlet weak var table: UITableView! override func viewDidLoad() { super.viewDidLoad() table.dataSource = self // Load `cellStates` if you need it... // (I could not find when you want to save it.) } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to List Sections
Thanks for showing the code. I could have reproduce the similar layout with the new code. (I used simplified layout because I could not make it work but that was enough. By the way, you should better follow the naming rule of Swift when you write code in Swift.) With this part: List(data) { data in Section(header: Text("GroupPicks")) { layout(data: data) } } You are trying to add a section to each row of your List. Which causes the result as shown in your previous screen shot. Putting Section inside List(data) { ... } does not make sense. Please try something like this: if data.count == 0 { Text("No Picks Found") } else { List { Section(header: Text("GroupPicks")) { ForEach(data) { data in layout(data: data) } } } .listStyle(GroupedListStyle()) //.listStyle(PlainListStyle()) //.listStyle(InsetListStyle()) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Array Elements - Getting Control
Unfortunately, the forums lack very important feature -- editing old posts. You may need to use Your Answer to show additional info. In addition, please show the complete definition of your Data. (Generally, you should better not use the same type name as very popular standard type names.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to save the state of a Switch
I want to save the state when there is a change to the switch state Please modify the code above as follows: class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource { //... override func viewDidLoad() { super.viewDidLoad() table.dataSource = self // Load `cellStates` if you need it... NotificationCenter.default.addObserver(self, selector: #selector(switchDidChange), name: .switchDidChange, object: nil) } @objc func switchDidChange(_ notification: Notification) { // Save `cellStates`... } } class SettingsCustomCell: UITableViewCell { //... @objc func switchValueChanged(sender: UISwitch) { state?.settingValue = sender.isOn NotificationCenter.default.post(name: .switchDidChange, object: self) } } extension Notification.Name { static let switchDidChange = Notification.Name("switchDidChange") }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Array Elements - Getting Control
If you say you would not like to show additional info using Your Answer, it is your choice. Hope you can solve your issue soon.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Ignoring keyboard safe area in action sheet
Can you show the complete code to reproduce the issue? Adding an image which describes what is wrong would be appreciated.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21