Re: filtering an array of entities using NSPredicate
Op 15 okt 2012, om 02:05 heeft Koen van der Drift het volgende geschreven: > > On Oct 14, 2012, at 7:56 PM, Willeke wrote: > >> the predicate should be something like >> name IN {"Jones A.", "Williams S.", "Brown M.", "Tobias S."} >> >> what is persons in this statement? >> [fetchRequest setPredicate: [NSPredicate predicateWithFormat: @"name IN %@", >> persons]]; > > 'persons' is an array of dictionaries, where one of the key-value pairs > contains the name. > > - Koen. It should be an array of strings: [fetchRequest setPredicate: [NSPredicate predicateWithFormat: @"name IN %@", [persons valueForKey:@"name"]]]; Willeke ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: filtering an array of entities using NSPredicate
So I cannot directly filter an array of dictionaries using a predicate? That was the whole goal of my question, see my original post. - Koen. On Oct 15, 2012, at 6:33 AM, Willeke wrote: > > Op 15 okt 2012, om 02:05 heeft Koen van der Drift het volgende geschreven: > >> >> On Oct 14, 2012, at 7:56 PM, Willeke wrote: >> >>> the predicate should be something like >>> name IN {"Jones A.", "Williams S.", "Brown M.", "Tobias S."} >>> >>> what is persons in this statement? >>> [fetchRequest setPredicate: [NSPredicate predicateWithFormat: @"name IN >>> %@", persons]]; >> >> 'persons' is an array of dictionaries, where one of the key-value pairs >> contains the name. >> >> - Koen. > > It should be an array of strings: > [fetchRequest setPredicate: [NSPredicate predicateWithFormat: @"name IN %@", > [persons valueForKey:@"name"]]]; > > Willeke > ___ > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/koenvanderdrift%40gmail.com > > This email sent to koenvanderdr...@gmail.com ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: filtering an array of entities using NSPredicate
On 2012 Oct 15, at 03:45, Koen van der Drift wrote: > So I cannot directly filter an array of dictionaries using a predicate? That > was the whole goal of my question, see my original post. Oh, now I see. I'd assumed that 'persons' was an array. It's a dictionary! But that should still work. According to the Predicate Programming Guide, "The collection may be an array, a set, or a dictionary – in the case of a dictionary, its values are used." But, again, I don't trust those things. Especially when they don't work :)) Try replacing persons with [persons allValues] in your format string. ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: filtering an array of entities using NSPredicate
On Mon, Oct 15, 2012 at 8:19 AM, Jerry Krinock wrote: > > On 2012 Oct 15, at 03:45, Koen van der Drift > wrote: > >> So I cannot directly filter an array of dictionaries using a predicate? That >> was the whole goal of my question, see my original post. > > Oh, now I see. I'd assumed that 'persons' was an array. It's a dictionary! Even better, it's an array of dictionaries! :-) - Koen. ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: filtering an array of entities using NSPredicate
On Oct 15, 2012, at 6:23 AM, Koen van der Drift wrote: > On Mon, Oct 15, 2012 at 8:19 AM, Jerry Krinock wrote: >> >> On 2012 Oct 15, at 03:45, Koen van der Drift >> wrote: >> >>> So I cannot directly filter an array of dictionaries using a predicate? >>> That was the whole goal of my question, see my original post. >> >> Oh, now I see. I'd assumed that 'persons' was an array. It's a dictionary! > > Even better, it's an array of dictionaries! :-) Willeke probably addressed your issue best. The contents of the collection that you pass to the aggregate expression must be the same type of value as the left hand expression. So, to have "name IN {ARRAY}", ARRAY *must* be an array of "name"s. In most cases, that will be strings. When you pass dictionaries, how is the predicate to know what value to use from the dictionary? There is no magic here. Other than how curiously the NSPredicate interpreted the array of dictionaries. Interesting, but not useful to your purpose. In any case, the predicate that you have shown is not valid for your case. Have you tried Willeke's suggestion? If it doesn't work, it doesn't mean that the predicate is bad, as -predicateWithFormat: is notorious for not working well with aggregate operations. Jerry Krinock's suggestion of constructing the predicate manually works most reliably, so that would be your next step to a solution. HTH, Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: filtering an array of entities using NSPredicate
On Mon, Oct 15, 2012 at 11:51 AM, Keary Suska wrote: > Willeke probably addressed your issue best. The contents of the collection > that you pass to the aggregate expression must be the same type of value as > the left hand expression. So, to have "name IN {ARRAY}", ARRAY *must* be an > array of "name"s. In most cases, that will be strings. When you pass > dictionaries, how is the predicate to know what value to use from the > dictionary? There is no magic here. Other than how curiously the NSPredicate > interpreted the array of dictionaries. Interesting, but not useful to your > purpose. In any case, the predicate that you have shown is not valid for your > case. > > Have you tried Willeke's suggestion? If it doesn't work, it doesn't mean that > the predicate is bad, as -predicateWithFormat: is notorious for not working > well with aggregate operations. Jerry Krinock's suggestion of constructing > the predicate manually works most reliably, so that would be your next step > to a solution. No, I haven't had a chance to try her solution yet, but that's the first on my list when I get back to my Mac. I have been playing a bit with the NSExpressions, but haven't had any luck with it. Again, a nice learning curve. - Koen. ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: filtering an array of entities using NSPredicate
I think this is the solution: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity: [NSEntityDescription entityForName: @"Person" inManagedObjectContext: context]]; [fetchRequest setPredicate: [NSPredicate predicateWithFormat: @"name IN %@", [persons valueForKey:@"name"]]]; [fetchRequest setResultType: NSDictionaryResultType]; NSError *error; NSArray *personsMatchingNames = [context executeFetchRequest: fetchRequest error: &error]; NSMutableArray *uniqueNames = [NSMutableArray arrayWithArray: persons]; [uniqueNames removeObjectsInArray: personsMatchingNames]; I also had to set the resulttype of the fetchrequest to NSDictionaryResultType. Thanks all for the help. - Koen. On Oct 15, 2012, at 11:51 AM, Keary Suska wrote: > > On Oct 15, 2012, at 6:23 AM, Koen van der Drift wrote: > >> On Mon, Oct 15, 2012 at 8:19 AM, Jerry Krinock wrote: >>> >>> On 2012 Oct 15, at 03:45, Koen van der Drift >>> wrote: >>> So I cannot directly filter an array of dictionaries using a predicate? That was the whole goal of my question, see my original post. >>> >>> Oh, now I see. I'd assumed that 'persons' was an array. It's a dictionary! >> >> Even better, it's an array of dictionaries! :-) > > Willeke probably addressed your issue best. The contents of the collection > that you pass to the aggregate expression must be the same type of value as > the left hand expression. So, to have "name IN {ARRAY}", ARRAY *must* be an > array of "name"s. In most cases, that will be strings. When you pass > dictionaries, how is the predicate to know what value to use from the > dictionary? There is no magic here. Other than how curiously the NSPredicate > interpreted the array of dictionaries. Interesting, but not useful to your > purpose. In any case, the predicate that you have shown is not valid for your > case. > > Have you tried Willeke's suggestion? If it doesn't work, it doesn't mean that > the predicate is bad, as -predicateWithFormat: is notorious for not working > well with aggregate operations. Jerry Krinock's suggestion of constructing > the predicate manually works most reliably, so that would be your next step > to a solution. > > HTH, > > Keary Suska > Esoteritech, Inc. > "Demystifying technology for your home or business" > ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
how to record audio from speaker on ios
I want to record video from iPad screen by AVCaptureSession & AVAssetWriter. now,i could capture video(include microphone sound)。but, The background music will stop when begin record video and the record will stop when play sound effect. My goal is capture the video include microphone sound , background music and sound sfx. How to fix the question? Thanks. ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com