• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Get list of possible applications
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get list of possible applications


  • Subject: Re: Get list of possible applications
  • From: Daniel <email@hidden>
  • Date: Sun, 20 Apr 2008 18:49:31 +0200

Hi,

thank you very much for your help, I was searching exactly that!

Best regards,
Daniel

On Sun, Apr 20, 2008 at 5:15 PM, Gerd Knops <email@hidden> wrote:
>
>  On Apr 19, 2008, at 11:33 PM, Chris Hanson wrote:
>
> > On Apr 19, 2008, at 9:55 AM, Gerd Knops wrote:
> >
> > > This returns an array with URLs of applicable applications for a file of
> a given URL:
> > >
> > > - (NSArray *)applicationsForURL:(NSURL *)url {
> > >
> > >        return (NSArray
> *)LSCopyApplicationURLsForURL((CFURLRef)url,kLSRolesAll);
> > > }
> > >
> >
> > It also leaks -- even if you're running under Objective-C garbage
> collection -- because LSCopyApplicationURLsForURL has "copy" in its name and
> therefore follows the Core Foundation "copy" rule.
> >
> >
>  Sorry, careless copying from a larger context and failure to proof read...
> Of course Chris is right.
>
>  Gerd
>
>
>
>
>
> > The proper form for the above method, if you aren't using Objective-C
> garbage collection, is:
> >
> >  - (NSArray *)applicationsForURL:(NSURL *)url {
> >     return [(NSArray *)LSCopyApplicationURLsForURL((CFURLRef)url,
> kLSRolesAll) autorelease];
> >  }
> >
> > This ensures that the returned NSArray will be autoreleased, instead of
> leaked.
> >
> > If you're using -- or might use -- Objective-C garbage collection, you'll
> want to replace the cast to (NSArray *) with NSMakeColectable like this:
> >
> >  - (NSArray *)applicationsForURL:(NSURL *)url {
> >     return [NSMakeCollectable(LSCopyApplicationURLsForURL((CFURLRef)url,
> kLSRolesAll)) autorelease];
> >  }
> >
> > The NSMakeCollectable ensures that the CFArrayRef returned by
> LSCopyApplicationURLsForURL will have its lifetime managed by the collector
> if GC is on, since -autorelease has no effect when GC is on.  This is also
> correct for non-GC, since NSMakeCollectable when GC is off is effectively
> just a cast from (CFTypeRef) to (id).
> >
> >  -- Chris
> >
> >
>
>

i,
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Get list of possible applications (From: Daniel <email@hidden>)
 >Re: Get list of possible applications (From: Gerd Knops <email@hidden>)
 >Re: Get list of possible applications (From: Chris Hanson <email@hidden>)
 >Re: Get list of possible applications (From: Gerd Knops <email@hidden>)

  • Prev by Date: Re: A cursor bug in DragItemAround example
  • Next by Date: Passing a C String as an argument
  • Previous by thread: Re: Get list of possible applications
  • Next by thread: Should a Method set NSError* to nil when No Error?
  • Index(es):
    • Date
    • Thread