Public Domain Classes

I have writing a program for way too long and have spent a lot of time looking at macoslib and Cocoa in general and have decided to write some cross-platform classes to implement extra functionality in a consistent way across Linux, Mac OS X and Windows… Right now, I only have the one component (they do take a while to write and test on all three platforms) but they will all be available in the directory

I used the prefix XF (Xojo Forum) as I am releasing them on here for anyone to use… See for more information about the licensing for these classes…

XFURL - represents a URL that can potentially contain the location of a resource on a remote server or the path of a local file on disk (pretty much like NSURL)

XFUserDefaults a simple preferences/settings class that uses a JSON object for the data store…

Handles: Strings, REALbasic.Rect, Pictures, Booleans, Number values
Should handle: Colours, Currency, Dates (haven’t used these in my project so no testing done, sorry)

Nice idea.

The only suggestions I have for you, is to use the actual OS X objects on OS X. For instance the XFURL object, if you use NSURL on OS X, you can then use bookmarks, which are one of the few ways to store references to files in a Sandboxed applications. Also bookmarks are now the only way to resolve Alias files on Yosemite (unless it’s a relative link, in which case you have to use a different function).

The same for the XFUserDefaults, on OS X either user NSUserDefaults or CFPreferences as either of these mechanisms will store the preferences correctly on OS X. For instance Apple have advised against manually reading/writing files in the preferences folder, Mavericks introduced issues if you do.

Thanks for the pointers Sam, originally I did have declares for the Mac OS X code, but decided to go this route for a couple of reasons…

XFURL - I was having issues with custom ports and NSURL when I upgraded to Yosemite (I remember it working properly on Mavericks)

XFUserDefaults - oddly enough I store my preferences in my Application Data folder, which allows for the whole thing to be portable, so I figured others would probably want the ability to write where ever as well…

I will add in the Cocoa declares as well incase anyone needs to use them (but you are probably just better off using macoslib or MBS plugins in that case)

Update XFURL to optionally use NSURL declares on Cocoa

[code]// current method and uses the RegEx code
DIM url As NEW XFURL(“”)

// new method and uses declares on Cocoa and RegEx everywhere else

ps… I figured out what I was doing wrong with the port property with NSURL so it works and submitted the code change to macoslib as well

Updated XFUserDefaults to fix an issue retrieving window bounds from the preference file…

It would be better if you could get specialists together from each platform to write the component for each platform and then you coordinate glueing it all together. As Sam said, ideally you would use the declares on the relevant platform, so for NSUserDefaults you would have someone write a component for OS X, one for Linux and one for Windows and then you glue it together finding the common properties and methods which apply to all three and name them to suit.

I have developed enough for Windows and Mac through the years to know that if both platforms can achieve the same things, emulating some of the Cocoa lib behaviors is tricky at best. For many reasons, the exact same features are not always possible.

The issue with declares is that they are inherently tied to one system, with all that comes with it. And one can easily see in this forum that if Mac and Windows do have a reasonable amount of declares available, Linux ones are rather anecdotal.

Xojo is an amazing accomplishment, with a high level of cross platform compatibility, as long as one sticks to pure Xojo. The result of 15 years development. As soon as one indulges in lower level calls to the system, it should be known that true cross platform largely becomes extremely difficult to achieve ; in practice, impossible.

Even if a team was to form to create components for every platform, there would be nobody for Linux.

As it stands, I find Shao Sean’s effort rather convincing, and appreciate his sharing.

Using declares has been done in macoslib and WFS (and I would highly recommend either of those to anyone)… MBS is another way to get the features (I believe Christian tries to take care of all three platforms)…

I am writing these for my own project to use and thought I would share… I am trying to have the same “features” on the three platforms and will code in Xojo to have the same code base…

All this has been released in to the public domain, so feel free to take it and add declares or whatever else you want… :slight_smile:

As far as I know, Christian is the only one here who has an intimate knowledge of Linux framework, enough to create amazing plugins. There is only one Linux thread in this whole forum with an actual listing containing the declare statement…

I did some Linux declares for the HTMLViewer, but I was probably helped out by Christian for that platform too (he showed me how to do the Windows declares)… I should just learn how to write plugins as writing C code is easier than writing the declares some times :wink:

XFNotificationCenter - A notification dispatch table to broadcast information within a program.
This works similar to NSNotificationCenter and it allows you to broadcast an event to registered observers within your program (this is only internal events)

I know the example project is pretty weak, but here are the commands:

XFNotificationCenter.AddObserver notificationObserver As Object, notificationName As String, notificationCallback As NotificationDelegate

  • notificationObserver object registering as an observer
  • notificationName name of the notification for which to register the observer
  • notificationCallback specifies the method that gets called to notify of the notification posting; this must have the signature: notificationSender As Object, userInfo As Dictionary

XFNotificationCenter.RemoveObserver notificationObserver As Object, notificationName As String

  • notificationObserver observer to remove
  • notificationName name of the notification to stop listening for

XFNotificationCenter.RemoveObserver notificationObserver As Object

  • notificationObserver observer to remove
  • note that this form removes the observer from all events

XFNotificationCenter.Notify notificationName As String, notificationSender As Object, userInfo As Dictionary

  • notificationName name of the notification
  • notificationSender object posting the notification. May be Nil
  • userInfo information about the the notification. May be nil


Been a while, but here is a one shot module that will format bytes into a human readable string… Supports both decimal and binary conversion of the bytes…

XFByteCountFormatter.StringFromByteCount(byteCount As UInt64, formatterStyle As XFByteCountFormatter.Style)

  • byteCount the byte count to be converted
  • formatterStyle whether to use decimal or binary math, optional, defaults to Decimal

I am updating the other XF modules/classes and will be putting them for download again in the near future… I am also going to be using semantic versioning on them, as well as all my new reusable classes/modules (I think it’s a good idea for all third party developers to take a look at it and perhaps adopt it)

Updated the classes and modules… Please note that some of these are not compatible with the ones posted above (all those links still work too)… I updated the web page so it looks a bit better and all the version numbers are listed as well… (incase the redirect doesn’t work)

all the links does not work except the XFByteCountFormatter

Sorry about that… I recompressed the files and didn’t remove the Xojo file extension… All fixed and added the XFWebView download link too (that one is in development and most of the work has been done on the Mac build, but the other two platforms will be getting some love soon… I think it might be really buggy on Windows right now as I was trying to add an EvaluteJavascript feature)

thanks… got all the files now…


What problems specifically? I’ve been using my own home rolled Plist Class for user prefs (derived from a now defunct 3rd party PD class years ago) for eons without a hitch, so what should I be looking out for?


I know there was mention of this for a few OS versions now… Apple doesn’t want you to directly write to the folder, but to use the Defaults feature of the OS… I guess this for a couple reasons - won’t break in a future version, consistent file format, no corrupt preference files, security and I am sure there are other reasons… Basically I use my class to write to the Application Data folder for my apps, but you can always use macoslib if you want to use NSUserDefaults and write to the proper place using the proper methods…

Exactly what Shao Sean says, the preferences folder is a remnant of the ‘classic’ days and Apple have advised against using it for a while now.

Mavericks was the first version where we start to see some changes, deleting the Plist file doesn’t always reset the preferences.

The easiest solution is to write your prefs to the App Support folder.

Ideally moving to Apple’s API, is the recommended way.

if you want to work with plist files, I would recommend using Apple’s API also. There are 4 different plist formats, a custom plist reader/writer may not support all formats and may get broken if Apple add a 5th. However if you’re using it for your own data files, then you don’t have anything to worry about.