I like to populate a structure with useful paths at app startup - e.g. path to current user’s home folder, where to store app preferences, that kind of thing.
One of the built in functions, SysUtils.GetAppConfigDir, is returning ‘/Users/(Username)/.config/…’ on macOS. I was expecting it to return the Application Support folder. I’ve come up with this little bit of code as an alternative - seems to work, so thought I’d share in case it proves useful:
{$MODESWITCH ObjectiveC1}
interface uses
Classes, SysUtils, CocoaAll, CocoaUtils;
…
function GetMacOSAppUserDataFolder:String;
var
paths:NSArray;
s:NSString;
begin
paths:=NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
NSUserDomainMask, True); //Fetch Application Support folder from user domain.
s:=NSString(paths.firstObject); //Cast first item found to NSString.
result:=NSStringToString(s).TrimRight(['/'])+'/'; //Ensure one trailing slash.
end;
This returns ‘/Users/(Username)/Library/Application Support/’