Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 22 in printed book and digital formats -- plus a one-year subscription (beginning with 23.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 23.2 ('Making Mancala')
Instant purchase and download via GumRoad!

COLUMN

Sorting Variants

Create Your Own Custom Sorting Methods

Issue: 23.2 (March/April 2025)
Author: Marc Zeedar
Author Bio: Marc taught himself programming in high school when he bought his first computer but had no money for software. He's had fun learning ever since.
Article Description: No description available.
Article Length (in bytes): 11,774
Starting Page Number: 59
Article Number: 23206
Resource File(s):

Download Icon project 23206.zip Updated: 2025-03-02 13:15:06

Related Link(s): None

Excerpt of article text...

If you're like me, you love that Xojo has a built-in method for sorting arrays: myArray.sort. Unfortunately, this only works with strings and numbers. If the array contains objects like folderItems, dateTime items, or your own custom class, it can't be sorted.

I've run into this so often that I have created utility routines that sort these by temporarily copying the items into a new array with the data in string format and sorting that. For example, for dates, I might convert them to SQLDate. Then I have to convert them back and replace the original array with the new one.

Since Xojo is so fast and my data needs aren't huge, this isn't a slow process—but it is inefficient and has always bugged me. Looking through Xojo's example projects, I noticed a sort example that takes a different approach. Here, we create our own compare method that gets passed to the sort routine, like this:

myArray.sort(addressOf dateCompare)

...End of Excerpt. Please purchase the magazine to read the full article.