Re: Need help with predicate format

2008-07-28 Thread Graham Cox


On 28 Jul 2008, at 1:52 pm, Omar Qazi wrote:

To be honest, I don't know if this will work, since I don't know if  
containsObject is checking if the argument is a pointer to an object  
in the array, or if it is equal to the object, but it's better than  
nothing, I guess.



From the docs:

containsObject:
Returns a Boolean value that indicates whether a given object is  
present in the receiver.


- (BOOL)containsObject:(id)anObject

Parameters

anObject
An object.

Return Value
YES if anObject is present in the receiver, otherwise NO.

Discussion
This method determines whether anObject is present in the receiver by  
sending an isEqual: message to each of the receiver’s objects (and  
passing anObject as the parameter to each isEqual: message).


Availability
• Available in Mac OS X v10.0 and later.




cheers, Graham___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Need help with predicate format

2008-07-28 Thread Fabian
Thanks. Maybe I should have made myself a little more clear. I don't
want to iterate over the array, but filter the array using a
NSPredicate.

I'm looking at the Predicate Programming Guide, which only gives basic
guidance, and the docs for NSExpression. It has several class methods
that sound right (expressionForEvaluatedObject:,
expressionForAggregate:,
expressionForSubquery:usingIteratorVariable:predicate:,
expressionForFunction:arguments:) but provides no examples how to use
them. Unfortunately Google has very little to say on this subject too.

To repeat the problem: I want to check the value of all keys in every
dictionary contained by an array and see if they match my search
string.

A workaround to compensate for my syntax ignorance would be to add a
new instance method to my custom class that simply return all the
values I want to check in a single array. Then I could query it with a
simple single-relationship predicate:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@(%@ IN
values, searchString)];
NSArray filteredArray = [myArray filteredArrayUsingPredicate:predicate];

But somehow I believe there is a more direct way to do this, without
having to add a new helper method to my class? I'm perfectly happy
with a 10.5 only solution.

Thanks.


On Mon, Jul 28, 2008 at 8:30 AM, Graham Cox [EMAIL PROTECTED] wrote:

 On 28 Jul 2008, at 1:52 pm, Omar Qazi wrote:

 To be honest, I don't know if this will work, since I don't know if
 containsObject is checking if the argument is a pointer to an object in the
 array, or if it is equal to the object, but it's better than nothing, I
 guess.


 From the docs:

 containsObject:
 Returns a Boolean value that indicates whether a given object is present in
 the receiver.

 - (BOOL)containsObject:(id)anObject

 Parameters

 anObject
 An object.

 Return Value
 YES if anObject is present in the receiver, otherwise NO.

 Discussion
 This method determines whether anObject is present in the receiver by
 sending an isEqual: message to each of the receiver's objects (and passing
 anObject as the parameter to each isEqual: message).

 Availability
• Available in Mac OS X v10.0 and later.




 cheers, Graham
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Need help with predicate format

2008-07-28 Thread Conrad Taylor
Hi, I would recommend taking a look at the following document.

http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/predicates.html
Good luck,

-Conrad

On Mon, Jul 28, 2008 at 1:02 AM, Fabian [EMAIL PROTECTED] wrote:

 Thanks. Maybe I should have made myself a little more clear. I don't
 want to iterate over the array, but filter the array using a
 NSPredicate.

 I'm looking at the Predicate Programming Guide, which only gives basic
 guidance, and the docs for NSExpression. It has several class methods
 that sound right (expressionForEvaluatedObject:,
 expressionForAggregate:,
 expressionForSubquery:usingIteratorVariable:predicate:,
 expressionForFunction:arguments:) but provides no examples how to use
 them. Unfortunately Google has very little to say on this subject too.

 To repeat the problem: I want to check the value of all keys in every
 dictionary contained by an array and see if they match my search
 string.

 A workaround to compensate for my syntax ignorance would be to add a
 new instance method to my custom class that simply return all the
 values I want to check in a single array. Then I could query it with a
 simple single-relationship predicate:

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@(%@ IN
 values, searchString)];
 NSArray filteredArray = [myArray filteredArrayUsingPredicate:predicate];

 But somehow I believe there is a more direct way to do this, without
 having to add a new helper method to my class? I'm perfectly happy
 with a 10.5 only solution.

 Thanks.


 On Mon, Jul 28, 2008 at 8:30 AM, Graham Cox [EMAIL PROTECTED]
 wrote:
 
  On 28 Jul 2008, at 1:52 pm, Omar Qazi wrote:
 
  To be honest, I don't know if this will work, since I don't know if
  containsObject is checking if the argument is a pointer to an object in
 the
  array, or if it is equal to the object, but it's better than nothing, I
  guess.
 
 
  From the docs:
 
  containsObject:
  Returns a Boolean value that indicates whether a given object is present
 in
  the receiver.
 
  - (BOOL)containsObject:(id)anObject
 
  Parameters
 
  anObject
  An object.
 
  Return Value
  YES if anObject is present in the receiver, otherwise NO.
 
  Discussion
  This method determines whether anObject is present in the receiver by
  sending an isEqual: message to each of the receiver's objects (and
 passing
  anObject as the parameter to each isEqual: message).
 
  Availability
 • Available in Mac OS X v10.0 and later.
 
 
 
 
  cheers, Graham
 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/conradwt%40gmail.com

 This email sent to [EMAIL PROTECTED]

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Need help with predicate format

2008-07-28 Thread Fabian
Thanks. As I said, I already read that but it doesn't give any
examples on how to format subqueries. Anyway, I ended up adding a
helper method to my subclass after all. It returns a single array of
keywords, which I can examine using a predicate with format (ANY
keywords contains[c] %@, searchString). It works fine. Perhaps even
faster than running a subquery, I dunno.

F.

On Mon, Jul 28, 2008 at 11:12 AM, Conrad Taylor [EMAIL PROTECTED] wrote:
 Hi, I would recommend taking a look at the following document.

 http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/predicates.html
 Good luck,

 -Conrad

 On Mon, Jul 28, 2008 at 1:02 AM, Fabian [EMAIL PROTECTED] wrote:

 Thanks. Maybe I should have made myself a little more clear. I don't
 want to iterate over the array, but filter the array using a
 NSPredicate.

 I'm looking at the Predicate Programming Guide, which only gives basic
 guidance, and the docs for NSExpression. It has several class methods
 that sound right (expressionForEvaluatedObject:,
 expressionForAggregate:,
 expressionForSubquery:usingIteratorVariable:predicate:,
 expressionForFunction:arguments:) but provides no examples how to use
 them. Unfortunately Google has very little to say on this subject too.

 To repeat the problem: I want to check the value of all keys in every
 dictionary contained by an array and see if they match my search
 string.

 A workaround to compensate for my syntax ignorance would be to add a
 new instance method to my custom class that simply return all the
 values I want to check in a single array. Then I could query it with a
 simple single-relationship predicate:

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@(%@ IN
 values, searchString)];
 NSArray filteredArray = [myArray filteredArrayUsingPredicate:predicate];

 But somehow I believe there is a more direct way to do this, without
 having to add a new helper method to my class? I'm perfectly happy
 with a 10.5 only solution.

 Thanks.


 On Mon, Jul 28, 2008 at 8:30 AM, Graham Cox [EMAIL PROTECTED]
 wrote:
 
  On 28 Jul 2008, at 1:52 pm, Omar Qazi wrote:
 
  To be honest, I don't know if this will work, since I don't know if
  containsObject is checking if the argument is a pointer to an object in
 the
  array, or if it is equal to the object, but it's better than nothing, I
  guess.
 
 
  From the docs:
 
  containsObject:
  Returns a Boolean value that indicates whether a given object is present
 in
  the receiver.
 
  - (BOOL)containsObject:(id)anObject
 
  Parameters
 
  anObject
  An object.
 
  Return Value
  YES if anObject is present in the receiver, otherwise NO.
 
  Discussion
  This method determines whether anObject is present in the receiver by
  sending an isEqual: message to each of the receiver's objects (and
 passing
  anObject as the parameter to each isEqual: message).
 
  Availability
 • Available in Mac OS X v10.0 and later.
 
 
 
 
  cheers, Graham
 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/conradwt%40gmail.com

 This email sent to [EMAIL PROTECTED]

 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/slasktrattenator%40gmail.com

 This email sent to [EMAIL PROTECTED]

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Need help with predicate format

2008-07-27 Thread Fabian
Hello,

I'm trying to understand how to use subquery expressions, but I just
don't... :-)

I have an array of MyCustomClass objects. MyCustomClass has a function
that returns an array of dictionaries. I want to query all keys in
each dictionary for a given string, i. e. something like (ANY
SELF.function.collection.keys.value contains %@, searchString). What
is the most efficient way to do this?

Thanks
F.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Need help with predicate format

2008-07-27 Thread Omar Qazi


On Jul 27, 2008, at 1:37 PM, Fabian wrote:


I want to query all keys in
each dictionary for a given string, i. e. something like (ANY
SELF.function.collection.keys.value contains %@, searchString). What
is the most efficient way to do this?


Well, NSArray has a method called containsObject: so,

for (NSDictionary *aDict in myObject.dictionaries) {
BOOL containsKey = [[aDict allKeys]containsObject:theKey];
//Do whatever you want with this
}

To be honest, I don't know if this will work, since I don't know if  
containsObject is checking if the argument is a pointer to an object  
in the array, or if it is equal to the object, but it's better than  
nothing, I guess.



Omar Qazi
Hello, Galaxy!
1.310.294.1593



smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]