Hi. I'm working my way through chapter 4 of the "Learning Core Audio" book. Before that I tried recording audio using the AudioToolbox with Swift. No matter what I do, I only record silence.
Having tried several examples from different sources I'm pretty sure my source code is not the issue. I enabled "Audio Input" for my target in XCode. I disconnected all external audio inputs and uninstalled a DAW that had created an aggregate I/O device. Still I'm not hearing anything from the file that's supposed to play my recorded audio.
Does anyone have an idea or has faced the issue before? Thanks in advance.
Post
Replies
Boosts
Views
Activity
Hi. I have a simple view:
struct ContentView: View {
var body: some View {
VStack {
List {
Text("Test")
}
}
.drawingGroup()
}
}
When I run my app I get an error message
Unable to render flattened version of ListRepresentable<SystemListDataSource, SelectionManagerBox>.
and a forbidden symbol:
This happens only with drawingGroup applied. Can't Lists be rendered with Metal?
Hi. I have a button that triggers a request to a webservice:
struct ContentView: View {
@StateObject private var state: State = State()
var body: some View {
VStack {
Button("Request", action: { makeRequest() })
Text(state.response)
}
}
private func makeRequest() {
URLSession.shared.dataTask(with: URL(string: "https://my-json-server.typicode.com/typicode/demo/posts/1")!, completionHandler: { data, _, _ in
state.response = String(bytes: data!, encoding: .utf8)!
})
.resume()
}
}
and an ObservableObject to store the response in:
class State: ObservableObject {
@Published var response: String = ""
}
.
It seems to workd, but, I get the error message
[SwiftUI] Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.
So I was wondering if this is the correct way to store the responses of HTTP requests in a StateObject. I also couldn't find anything about receive(on:).
I tried the example from https://developer.apple.com/documentation/swiftui/editmode. It's not working for me.
struct ContentView: View {
@Environment(\.editMode)
private var editMode
@State
private var name = "Maria Ruiz"
var body: some View {
NavigationView {
Form {
Text(String(editMode!.wrappedValue.isEditing))
if editMode?.wrappedValue.isEditing == true {
TextField("Name", text: $name)
} else {
Text("test")
}
}
.animation(nil, value: editMode?.wrappedValue)
.toolbar { // Assumes embedding this view in a NavigationView.
EditButton()
}
}
}
}
It shows the texts "false" and "test", before and after clicking Edit. What am I missing? I'm using XCode 14.0.1 and the deployment target is iOS 16. I also tried on a real iPhone and on iOS 15.5 in the Simulator. Thanks for any help.
I have a NavigationSplitView and an EditButton in the same ContentView. Both do what they should, except that when I click "Edit" and then "Done", the detail view of the last selected item in my list appears. This happens only after I have clicked one of the list items, not before.
This is my code:
var body: some View {
NavigationSplitView {
List(selection: $selectedItem) {
ForEach(items, id: \.self) { item in
Text(item.timestamp!, formatter: itemFormatter)
}
.onDelete(perform: deleteItems)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
Text("Select an item")
} detail: {
NavigationLink(value: selectedItem) {
Text("Item")
}
}
}
The problem doesn't exist with a NavigationStack. Is there any way to get around this?
I have a view that is part of a larger view. I have a preview of that part, but XCode draws a device (some iPhone model by default) around it. I can choose a different device with .previewDevice(PreviewDevice(rawValue: "...")). I found a screenshot of what I want to do, so I assume it's possible somehow:
Unfortunately where I found the screenshot was not described how to do this. I tried previewDevice(.none), but that at least didn't do what I want. I'm using XCode version 14.3 Release Candidate, but can switch back version 14.2. Does anyone have an idea?