In the AudioBufferList extension, there is a comment above the allocate function
/// The memory should be freed with `free()`.
public static func allocate(maximumBuffers: Int) -> UnsafeMutableAudioBufferListPointer
But when I try to call free on the returned pointer,
free (buffer)
XCode complains:
Cannot convert value of type 'UnsafeMutableAudioBufferListPointer' to expected argument type 'UnsafeMutableRawPointer?'
How should the pointer be free'd?
I tried
free (&buffer)
XCode didn't complain, but when I ran the code, I got an error in the console.
malloc: *** error for object 0x16fdfee70: pointer being freed was not allocated
I know the call to allocate was successful.
Thanks,
Mark
Post
Replies
Boosts
Views
Activity
My MacOS program is printing a message in the terminal window in XCode
networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception.
How do I do this? I don't see a way to add arbitrary File Access on the Signing & Capabilities tab under app setup.
XCode 13.3.1
OSX Monterey 12.3.1
Mac Mini M1
I used the Xcode template to create a Mac App. I then modified ContentView.swift
import SwiftUI
import MapKit
struct ContentView: View {
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: 0.0,
longitude: 0.0),
span: MKCoordinateSpan(
latitudeDelta: 0.5,
longitudeDelta: 0.5))
var body: some View {
Map(coordinateRegion: $region)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
When I run this code, Xcode reports a runtime error:
Modifying state during view update, this will cause undefined behavior.
It is reported on Thread 1.
This is identified with a purple warning in the issue navigator, but there is no indication of the location of the error in the source code editor.
The actual map coordinates don't matter. I get the same error with different coordinates.
Xcode 13.3.1
OSX Monterey 12.3.1
Mac Mini M1
P.S. When I cut the example code above from Xcode and pasted it into this message, it added extra line breaks between each line (which I manually removed). Is there a way to have the code paste as it was in Xcode?
P.P.S. When I listed the software and hardware info, If I don't make it a bulleted list, the ended up being displayed on one line. If I put blank lines between them, the blank lines are displayed. Is there any way to make a vertical list without bullets?
If you use a TabView in a Preferences scene you get nice looking tabs.
If you use a TabView in the main scene, the tabs are plain.
Is there a way to fix that?
Thanks, Mark
I have seen code where a struct is defined and then in the same file an extension for the same struct is defined. Why not just include the contents of the extension in the original struct definition?
I'm trying to create a custom control similar to a DisclosureGroup.
I would like to align the leading edges of "11" and "First". There is a Button preceding "First", but none preceding "11".
Bonus question. I'm using SF Symbols for the arrows, but I would like to use the > and V used in DisclosureGroup. Are those symbols available?
Thanks, Mark
var body: some View {
List(items, selection: $selection) { master in
HStack {
if master.master {
Button {
if master.master {
expanded.formSymmetricDifference([master.id])
}
} label: {
Image(systemName: expanded.contains(master.id) ? "arrowtriangle.down" : "arrowtriangle.forward")
}
.buttonStyle(BorderlessButtonStyle())
}
Text(master.name)
}
}
.frame(width: 200)
}
While I appreciate the work that Apple puts into the developer documentation, I find it very hard to use.
Among other things, I'm looking for a reference (free / paid / online / dead tree) that describes the views available in SwiftUI with the applicable view modifiers and examples of how to use them.
.commands{
SidebarCommands()
}
If I add the above to a MacOS app, the program gains a Show Sidebar / Hide Sidebar menu option on the View menu. I'd like to add a button to show or hide the sidebar such as the one in Xcode, but I can't find a way to do it? I would have thought that there would be a simple framework call, but my internet searches haven't turned up anything.
I also like the way that Xcode places the Hide Sidebar button on the sidebar, but when the sidebar is hidden, the Show Sidebar button is on the left side of the window. Has any one figured out how to do this with SwiftUI?
This morning the Canvas preview on the app I am developing starting displaying "Cannot preview in this file...". The diagnostics display complains:
MessageSendFailure: Message send failure for send previewInstances message to agent
==================================
| RemoteHumanReadableError
|
| LoadingError: failed to load library at path "/Users/mark/Library/Containers/com.microenh.BoxDesigner/Data/MainView.1.preview-thunk.dylib": Optional(dlopen(/Users/mark/Library/Containers/com.microenh.BoxDesigner/Data/MainView.1.preview-thunk.dylib, 0x0002): tried: '/Users/mark/Library/Developer/Xcode/DerivedData/BoxDesigner-gbhzycedtosmdoetkpwtcpuwawhb/Build/Intermediates.noindex/Previews/BoxDesigner/Products/Debug/MainView.1.preview-thunk.dylib' (no such file), '/Users/mark/Library/Containers/com.microenh.BoxDesigner/Data/MainView.1.preview-thunk.dylib' (code signature in <D4EED909-712E-3055-B429-BBA7EB77A196> '/Users/mark/Library/Containers/com.microenh.BoxDesigner/Data/MainView.1.preview-thunk.dylib' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)))
The file /Users/mark/Library/Containers/com.microenh.BoxDesigner/Data/MainView.1.preview-thunk.dylib is present.
I tried deleting the /Users/mark/Library/Containers/com.microenh.BoxDesigner folder and rebuilding. No change.
I have a Mac Mini M1 with OSX Monterey. I just upgraded to 12.4. I'm currently using Xcode 13.4, but I've had this problem for a while now.
I have two Acer CB282K monitors. CB282K(2) is connected to the Mini's HDMI port and is configured as the main display. CB282K(1) is connected to a USB-C port via a USB-C / HDMI adapter and is configured as extended. Both monitors appear to be working perfectly.
If I hover my mouse over the green button at the top of the most windows, one of the pop up options is "move to CB282K(1)" or "move to CB282K(2)" depending on which monitor is currently displaying the window.
This works fine with most if not all of my programs (including Mail and Safari), but not with Xcode. When I first open any window, while the option is there, selecting it does not move the window to the other monitor. However, if I drag the window to the other window, the option works to move the window back and forth between the monitors. If I close the window and re-open it, it is again "locked" to the main display until I drag it.
I see this behavior with the first Xcode window I open, with a second Xcode window I open (say I want to view two projects at the same time), or with the Developer Help window.
I'm pretty sure that when I started with Xcode last summer, this feature worked, but it has stopped at some point in the past.
I am currently working with XCode 13.3.1 on OSX Monterey 12.3.1 on a Mac Mini M1. I have written some programs in Swift for personal use using a personal team certificate. I haven't paid the $99.
Every couple of weeks or so, some of my programs will pop up a message saying "This Program Could Harm Your Mac" and won't let me run it when I try to launch them. It seems I have to recompile it and then it will work for a few more weeks. Other programs have run for several months.
The programs are using Sandbox and Hardened runtime.
Someone suggested that I try compiling the program without a certificate. I did that last night and the program ran. But this morning when I launched the program, I got a message that the program had unexpectedly quit. The "report" message said something about a code signature.
FWIW, I am copying the program to my Applications folder.
Can someone tell me how Xcode provides the row of images (see above) at the top of the Navigator panel to switch among the various options? It does the same thing with the Inspector panel.
Thanks, Mark
I'm looking for some in-person contacts to help me learn MacOS programming. I'm willing to share what I've learned.
Thanks,
Mark
func zoomOne() {
region.span.latitudeDelta = 10_000
region.span.longitudeDelta = 10_000
}
func zoomIn() {
region.span.latitudeDelta /= 2
region.span.longitudeDelta /= 2
}
func zoomOut() {
region.span.latitudeDelta *= 2
region.span.longitudeDelta *= 2
}
My MacOS app has three methods for adjusting the zoom on a MapKit map display. Each is tied to a separate view Button.
zoomIn() and zoomOut() work as expected, but when the program calls zoomOne(), Xcode breaks and reports a runtime issue in the Issue Navigator:
NSHostingView is being laid out reentrantly while rendering its SwiftUI content. This is not supported and the current layout pass will be skipped.
As a fix, I tried embedding the zoomOne() region update in a DispatchQueue.main.async closure, but it still failed with the same issue.
Thanks, Mark
I have an app that displays a MapKit map with a Text as an a MapAnnotation. When the map is first displayed, the map is centered on the coordinates of the MapAnnotation and once things settle down, the CPU usage reported by Xcode's Debug Navigator goes to 0%.
If the map is dragged or zoomed so that the MapAnnotation is not at the center, the CPU usage goes up during the motion, but does not go back to 0%, but settles down to a few per cent. If you look closely at the map, you can sometimes see that the MapAnnotation is vibrating. Other map features do not appear to move.
I assume that the MapAnnotation is not tied to a fixed map location as are the map features and if the MapAnnotation is not at the center, its display position needs to be constantly recalculated.