discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GSPredicate


From: David Chisnall
Subject: Re: GSPredicate
Date: Mon, 18 Jun 2018 16:46:47 +0100

On 18 Jun 2018, at 16:32, amon <amon@vnl.com> wrote:
> 
> Just to bring this back to my original question:
> 
> NSUInteger i;
> NSMutableArray *a;
> NSEnumerationOptions opts;
> GSPredicateBlock      predicate;
> 
> i = [a indexOfObjectWithOptions: opts passingTest: predicate];
> 
> What is the code to set up predicate using the GSBlock macro?
> Can someone show me what the above would look like as a working
> bit of code?

You cannot create blocks with a compiler that does not support blocks.

If you look at the declaration of this, or Appleā€™s documentation, you will see 
that it expects a block of the form:

        BOOL(^)(id obj, NSUInteger idx, BOOL *stop)

You must therefore write such a block.  For example:

```objective-c
GSPredicateBlock predicate = ^()(id obj, NSInteger idx, BOOL *stop)
{
        if ([obj passesSomeTest])
        {
                // Include this one
                return true;
        }
        else if (idx = 32)
        {
                // Unconditionally include the thing at index 32, even if it 
fails the test.
                return true;
        }
        if ([obj isInvalid])
        {
                // If we find any invalid objects, then give up completely.
                *stop = YES;
        }
        return false;
}
```

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]