Hello,
I am trying to download a macOS image with the swift code bellow. I would like to update a NSProgressIndicator component to show download progress.
The closure is run on a background thread so i need to do something to force execution on main thread. This is what i am trying to do with DispatchQueue.main.async but it does not work. I have also tried with DispatchQueue.global().async (and both).
I have a runtime error saying i can't update UI from background thread.
I don't understand why DispatchQueue.main.async does not force execution on main thread.
Do you have any idea ?
Thanks
@IBOutlet weak var progression: NSProgressIndicator!
...
func method1()
{
let downloadTask = URLSession.shared.downloadTask(with: restoreImage.url) { localURL, response, error in
...
downloadObserver = downloadTask.progress.observe(\.fractionCompleted, options: [.initial, .new]) { (progress, change) in
DispatchQueue.global().async
{
DispatchQueue.main.async
{
self.progression.doubleValue = (change.newValue! * 100) // Execution error on this line
}
}
...
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello,
I am downloading macOS restore image with VZMacOSRestoreImage, in order to deploy virtual machines.
I have just upgraded my host mac to last Sonoma version.
So, macOS restore image has just been downloaded on my computer during upgrade procedure.
Is there a way to avoid a second download and ask VZMacOSRestoreImage to fetch my last local macOS image ? I think this image is still stored somewhere on my computer...
Thanks
Hello,
It is possible to encrypt a mac's hard-drive with Filevault.
All home user folders are encrypted with the same encryption key. (This is the same encryption key for the whole hard-drive).
This encryption key is encrypted with user password. But i don't understand how it works when there are multiple user accounts. Maybe there is a table: The same encryption key is stored several times (one per user account) ?
Is there a way for a user to read the filevault encryption key ?
Thanks
Hello,
I have read com.apple.security.app-sandbox entitlement is required for macOS applications distributed through appstore.
If so, how can it be possible for an application like Microsoft Word to read/write files in Documents folder ? It should be forbidden, due to sandbox ?
Thanks
Hello,
I have an encrypted dmg file containing a secret file.
When a user want's to see the secret, he must mount the dmg and provide password.
When the dmg is mounted, every user connected to the computer can see the secret file ! And i don't want this.
Is there a way to open a dmg file with swift language, without mounting it ?
Thanks
Hello,
I do not understand something in my code bellow:
@Observable
class Dog: Identifiable
{
var name = "Test"
var age = 3
}
struct ContentView: View {
@State private var model = Dog()
let nf = NumberFormatter()
var body: some View {
Form
{
Section
{
TextField("Name", text: $model.name)
}
Section
{
TextField("Age", text: $model.age, formatter: nf)
}
}
}
}
I have a compilation error: "Trailing closure passed to parameter of type 'FormStyleConfiguration' that does not accept a closure"
If i remove the age TextField, everything works fine.
Do you have any idea ? Maybe i have made something wrong with text formatter ?
Thanks
Hello,
I am wondering the value-add of autorelease in swift.
Look at this code:
for i in (0...10)
{
autorelease
{
let obj1=MyClass()
...
}
}
obj1 will be released at the end of autorelease block.
But i can also work with a function like this (or a closure):
func test()
{
let obj1=MyClass()
...
}
for i in (0...10)
{
test()
}
obj1 will be released at the end of the test function.
Do you agree we have the same result in memory in both cases ?
If so, when should we work with autorelease ?
Thanks
Hello,
I am read some binaries are "SIP protected".
SIP means System Integrity Protection.
I know this is a security mechanism under macOS.
But i don't understand what is a "SIP protected binary".
Is it a binary located in a specific folder ? Is it a binary signed with "hardened runtime" ?
Thanks
Hello,
I have create a dynamic library with gcc:
gcc -dynamiclib liblib1.c -o liblib1.dylib
I have create a binary which needs this dynamic library:
gcc -L./ -llib1 test.c -o test
I have looked at mach-o commands in test binary. I have seen the library is loaded with LC_LOAD_WEAK_DYLIB. How can i load the library with LC_LOAD_DYLIB instead of LC_LOAD_WEAK_DYLIB ?
And i have a second question: Is it possible to compile the binary with a static linking of the library ? I have tried with -static option, like i do on Linux but it does not work on macOS and i don't understand why...
Thanks
Hello,
I have tried to create a thread with thread_create_running API.
It works but i would like to suspend this thread. I can call thread_suspend, but my thread has already been start before i call this API.
Is there a way to create a thread without running it automaticaly.
Thanks
Hello,
Let's imagine an application (Application A) which launch another application (Application B). These applications are bundle apps.
What happens if Application B tries to read a file in current user's Documents folder ?
TCC will check if the application is allowed to access to Documents folder. But will it check this right for application A or application B (or both ?)
I have tried to run an application from Terminal. My terminal is authorized to access to Documents folder. And i am surprised because TCC did not asked me to allow the application itself. It seems TCC is looking for parent process rights. Can you confirm ?
Thanks
Hello,
I am trying to create a dmg file by launching hdiutil through my swift program.
This swift program is sandboxed.
Here is what i've done:
let hdd_file:String = NSHomeDirectory() + "hdd.dmg.sparseimage"
let process = Process()
process.launchPath = "/usr/bin/hdiutil"
process.arguments = ["create", "-size", "30g", "-fs", "'APFS'", "-volname", "myvolume", "-type", "SPARSE", hdd_file]
let pipe = Pipe()
process.standardOutput = pipe
process.launch()
let data = try pipe.fileHandleForReading.readToEnd()
print(data)
I get this error:
hdiutil: create failed - Device not configured
I don't understand why i get this error because the dmg file is created in application's sandbox home directory.
Or maybe hdiutil is forbidden but i am just creating a dmg file. I am not trying to mount a device.
Do you have any idea of how i can create a dmg file from my sandboxed application ?
Thanks
Hello
I have looked at Virtualization framework samples source code provided by Apple.
There is something strange: For a linux guest OS, i can see a variable store:
let variableStore = try VZEFIVariableStore(creatingVariableStoreAt: xxxx)
...
let bootloader = VZEFIBootLoader()
...
bootloader.variableStore = variableStore
It seems this variable store is linked with NVRAM.
For a macOS guest OS, there is no variable store. (The bootloader is created with VZMacOSBootLoader)
My question is why macOS guest doesn't need variable store ?
Thanks
Hello,
I am working with Virtualization framework in an Xcode swift project.
I have also installed Parallels Desktop on my mac (Apple Silicon).
I would like to convert a Parallels Desktop hard drive (hds file) to an image compatible with my Virtualization framework project.
My goal is to run my Parallels Desktop virtual machine in my Xcode project.
Is there a way to do that ?
Thanks
I would like to develop a macOS application in Swift. This application will consist of 2 programs: a main program to be run by the user (standard account) and another one that will run with root privileges. The second program will only be invoked to perform privileged tasks. Running the main program under root permanently would be too risky.
XPC will be used to trigger calls from the main program to the privileged program.
How can I secure the privileged program to ensure that the calling program is indeed my main program and not another unauthorized program?