Array.add() missing from epix simulator

The epix simulator seems to have problems with Toybox.Lang.Array.add() method. The sample code works in other simulators.

To reproduce, clone the repository
https://github.com/samuelmr/garmin-updatecount

Run
monkeyc -f monkey.jungle -d epix -y ~/connectiq/developer_key.der -o UpdateCount.prg connectiq monkeydo UpdateCount.prg epix
Result:
Could not find symbol 'add' Symbol Not Found Error in onUpdate (.../UpdateCount/source/UpdateCountView.mc:28)
  • add() for an array because available with CIQ 1.3.0, and the Epix is still running CIQ 1.2.x, so it's not available on an Epix. You need to implement your own version of add
  • Thanks!

    I tried to find information about CIQ versions the devices are running. https://developer.garmin.com/connect-iq/compatible-devices/ explains that some of them are running v1 and some v2 but not the minor versions.

    Is it correct to assume that the connectiq/bin/devices.xml is the documentation I should refer to or is there a more human-readable resource available?

    For the Connect IQ team, this ticket can be closed.
  • In the case of the Epix, that's the really odd one as it's the only one that's still 1.2.x - that version of CIQ is from 2016.

    When you go to run it, in the run config, the only target SDK available is 1.2.x. The API doc includes "since" for most things, so in the case of add() for an Array, "since" is 1.3.0.

    Supporting the Epix is a challenge unless you have one, and the epix really isn't that common for users. You may find things in the sim that aren't quite correct and won't know until a user sees it. Out of my 50 or so apps in the store, I might have one that's supported on the Epix, and honestly can't remember that last time a user has asked for something to be supported on the Epix.

    A note about add() with arrays - for large arrays, you want to be careful, as you'll see a spike in memory usage when it happens. It has the memory for the original array, then allocates memory for the new size and copies the old to the new, so a large array will take twice the space for a bit. It may work better if you know a max size for the array, and then save an index as to what's been used.
  • Hello, could you please elaborate or even better if I can trouble you to provide example how one can implement "add to array" in SDK 1.2.x?

    Also, indexOf() is quite necessary.

    From what i see only size() is supported.

    Thanks,

    Igor.

  • Get the size of the current one, get a new array that's +1 in size, and copy old to new, and but what you want to add at at the end

  • It seems to me that Array.indexOf() can also be re-implemented, by iterating through the entire array, and using Object.equals() to compare the array elements to the object of interest.

  • function myAdd(curArray,newValue) {
        var curSize=curArray.size();
        var newArray=new [curArray.curSize+1];
        for(var i=0;i<curSize;i++) {newArray[i]=curArray[i];}
        newArray[curSize=newValue;
        return newArrray;
    }
    
    // called with
    array=myAdd(array,value);

    You could run into watchdog issues if curSize is large.

    Like flowstates says, walk the array, but you may want the first, last, or all that are the same, and based on what's in the array you may want to use = instead of equals().

    So for an array of Numbers/floats where you want the first occurance:

    function myIndexOf( array, value) {
        for(var i=0;i<array.size();i++) {
            if(array[i]==value) {return i;}
        }
        return null;
    }