private void RunQuery()
    {
        // The objective-c version takes a format string and a variadic argument
        // list for substititon, but we only support sending an unformatted string
        // down. Marshalling variadic arguments is tricky....
        // Just do your formatting on the C# side.

        // Note that passing a bad predicate string will throw an exception

        // Pick a random name out of the hat
        var queryStr = string.Format("name = '{0}'", names[UnityEngine.Random.Range(0, names.Length)]);

        Debug.Log(string.Format("Running query with predicate ({0})", queryStr));

        // Queries are made with NSPredicate which sorta like SQL and sorta
        // like regular expressions.
        // See https://nshipster.com/nspredicate/ for a quick intro to the kinds
        // of queries you can run. Were just going to do a simple key,value search
        CKQuery query = new CKQuery("Person", NSPredicate.PredicateWithFormat(queryStr));

        // The second argument here is the container to search in. Unless you
        // are using custom containers, you'll want to pass null for the
        // default container

        database.PerformQuery(query, null, OnQueryComplete);
    }
Esempio n. 2
0
    private IEnumerator RunQueryCo()
    {
        Debug.Log("waiting 5 seconds before running query...");
        yield return(new WaitForSeconds(5f));

        Debug.Log("fetching sorted...");

        // Sort - alphabetically for the primary key, reverse alphabetically for the second
        var primarySort = new CKQuery(recordType, NSPredicate.PredicateWithValue(true));

        primarySort.SortDescriptors = new NSSortDescriptor[]
        {
            new NSSortDescriptor(primaryFieldKey, true),
            new NSSortDescriptor(secondaryFieldKey, false)
        };

        database.PerformQuery(primarySort, null, OnQuery);
    }