Environment.UserLibraryFolder returns Nil in Swift

I am developing on Windows 10 and when trying to get the path to my AppData folder via ElementsRTL, I am calling Environment.UserLibraryFolder and it is kicking out with Nil. This is a bug?

I believe Environment.UserLibraryFolder is specific to macOS.

    property UserHomeFolder: nullable Folder read GetUserHomeFolder;
    property DesktopFolder: nullable Folder read GetDesktopFolder;
    property TempFolder: nullable Folder read GetTempFolder;
    property UserApplicationSupportFolder: nullable Folder read GetUserApplicationSupportFolder; // Mac only
    property UserLibraryFolder: nullable Folder read GetUserLibraryFolder; // Mac only
    property UserDownloadsFolder: nullable Folder read GetUserDownloadsFolder;
    property SystemApplicationSupportFolder: nullable Folder read GetSystemApplicationSupportFolder; // Mac only

I’ll look into exposing AppData too, and to see what the best option for exposing an option that can be shared cross-platform. If anything, UserApplicationSupportFolder might be the closest match to AppData, not UserLibraryFolder — maybe I’ll map that one.

Maybe I am not reading the help file correctly, doesn’t this reflect it should work on .net?

.NET code can run on macOS, just like native macOS binaries can; in both cases these will be valid, which is why they are available to for the .NET platform.

Ahhh, thanks so much!

1 Like

marc,

I am guessing the screen clip you included was from the source file? It seems the documentation should highlight platform or language exclusions, as opposed to looking at the source (but I will look at the source before posting a question again!)

it was, and it should; yes. im also debating whether these should raise an exception on platforms where they aren’t supported (and where we can’t do a compile-time check, like .NET), rather than return nil (and I’ll mark them as unavailable for platforms wheree know at compile-time they aren’t.