private void ModifyRecord()
    {
        // There's no "modify record" operation in cloud-kit. To modify a record
        // you just re-save a record whose 'RecordChangeTag' matches the tag on
        // the server. This ensures that you are always modifying the most recent
        // version of the record.

        // For a single client application, this should always be the same

        // So let's change a few values and re-save the record

        // Cloudkit stores both fixed and floating percision types in the same
        // Number type
        record.SetInt(UnityEngine.Random.Range(0, int.MaxValue), "MyNumber");
        record.SetDouble(UnityEngine.Random.Range(0f, float.MaxValue), "MyNumber");

        // You can also store arbitrary byte data
        byte[] bytes = Encoding.ASCII.GetBytes("Test Buffer");
        record.SetBuffer(bytes, "TestBufferKey");

        // You can't change the type of a field you set previously
        // This would generate an error...
        // record.SetInt(0, "MyField");

        database.SaveRecord(record, OnRecordModified);
    }
Beispiel #2
0
    public void Can_set_and_retrieve_int_by_key()
    {
        var record   = new CKRecord("record_type");
        var intKey   = "int_key";
        var intValue = 42;

        record.SetInt(intValue, intKey);

        Assert.AreEqual(record.IntForKey(intKey), intValue);
    }
Beispiel #3
0
    public void All_keys_has_all_the_keys()
    {
        var record = new CKRecord("record_type");
        var keys   = new string[] { "string_key", "bool_key", "int_key", "double_key", "buffer_key", "asset_key", "reference_key" };

        record.SetString(keys[0], "string_value");
        record.SetInt(1, keys[1]);
        record.SetDouble(1f, keys[2]);
        record.SetBuffer(new byte[] { }, keys[3]);
        record.SetAsset(new CKAsset(null), keys[4]);
        record.SetReference(new CKReference(new CKRecordID("record"), CKReferenceAction.DeleteSelf), keys[5]);

        var allKeys = record.AllKeys();

        foreach (var key in allKeys)
        {
            Assert.IsTrue(allKeys.Contains(key));
        }
    }