Hi,
I need to translate this native Cocoa message [NSFileManager URLsForDirectory: NSApplicationSupportDirectory inDomains: NSUserDomainMask] to PB CocoaMessage.
This message should return the equivalent of AppData on Windows, but on Mac OSX (probably something like: "/Users/USERNAME/Library/Application Support/")
I've checked this thread: http://www.purebasic.fr/english/viewtop ... 98#p410298 but the message here is structured differently, and I don't get it and it is very frustrating .
Could someone help me on this and give a little explanation on how this message is structured ? (not the solution alone please)
Thanks in advance!
Cheers,
Guy.
Call To NSFileManager
- grabiller
- Enthusiast
- Posts: 309
- Joined: Wed Jun 01, 2011 9:38 am
- Location: France - 89220 Rogny-Les-Septs-Ecluses
- Contact:
Call To NSFileManager
guy rabiller | radfac founder / ceo | raafal.org
Re: Call To NSFileManager
You have to take into account that the FileManager method URLsForDirectory:inDomains: returns an array of URLs. The first (and only) element in the resulting array has to be converted from an NSURL to an NSString, from an NSString into an UTF8 String and finally into a PB string:
Code: Select all
#NSApplicationSupportDirectory = 14
#NSUserDomainMask = 1
FileManager = CocoaMessage(0, 0, "NSFileManager defaultManager")
URLArray = CocoaMessage(0, FileManager,
"URLsForDirectory:", #NSApplicationSupportDirectory,
"inDomains:", #NSUserDomainMask)
If URLArray
Debug PeekS(CocoaMessage(0, CocoaMessage(0,
CocoaMessage(0, URLArray, "objectAtIndex:", 0), "path"),
"UTF8String"), -1, #PB_UTF8)
EndIf
- grabiller
- Enthusiast
- Posts: 309
- Joined: Wed Jun 01, 2011 9:38 am
- Location: France - 89220 Rogny-Les-Septs-Ecluses
- Contact:
Re: Call To NSFileManager
Thanks a lot Shardik, works perfectly.Shardik wrote:You have to take into account that the FileManager method URLsForDirectory:inDomains: returns an array of URLs. The first (and only) element in the resulting array has to be converted from an NSURL to an NSString, from an NSString into an UTF8 String and finally into a PB string:Code: Select all
#NSApplicationSupportDirectory = 14 #NSUserDomainMask = 1 FileManager = CocoaMessage(0, 0, "NSFileManager defaultManager") URLArray = CocoaMessage(0, FileManager, "URLsForDirectory:", #NSApplicationSupportDirectory, "inDomains:", #NSUserDomainMask) If URLArray Debug PeekS(CocoaMessage(0, CocoaMessage(0, CocoaMessage(0, URLArray, "objectAtIndex:", 0), "path"), "UTF8String"), -1, #PB_UTF8) EndIf
Cheers,
Guy.
guy rabiller | radfac founder / ceo | raafal.org
Re: Call To NSFileManager
As an alternative you can use NSSearchPathForDirectoriesInDomains which is a function that returns an array of NSString objects instead of NSURL objects.Shardik wrote:You have to take into account that the FileManager method URLsForDirectory:inDomains: returns an array of URLs. The first (and only) element in the resulting array has to be converted from an NSURL to an NSString, from an NSString into an UTF8 String and finally into a PB string
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)