• 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
NSRunningApplication executableURL issue in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSRunningApplication executableURL issue in Swift


  • Subject: NSRunningApplication executableURL issue in Swift
  • From: Bill Cheeseman <email@hidden>
  • Date: Tue, 10 Mar 2015 12:24:21 -0400

I'm using Xcode 6.2 and Swift 1.1.

1. The following statement reports the error "'NSURL?' does not have a member named 'path'" even though executableURL has a trailing exclamation point to unwrap it. The caret identifying the location of the error is placed under the exclamation point.

for thisApp in NSWorkspace.sharedWorkspace().runningApplications {
     let thisPath = thisApp.executableURL!.path // ERROR
}

If I change executableURL to bundleURL, the error goes away. Yet executableURL and bundleURL are declared identically according to the NSRunningApplication reference document. As far as I know, bundleURL and executableURL both satisfy fileURL.

The error also goes away if I assign thisApp to a local variable and expressly downcast it to NSRunningApplication, as shown below. Why would I need to do that with executableURL, when it isn't necessary with bundleURL?

for thisApp in NSWorkspace.sharedWorkspace().runningApplications {
     let myAppAndIMeanIt = thisApp as NSRunningApplication
     let thisPath = myAppAndIMeanIt.executableURL!.path // NO ERROR
}

Is this a Swift bug?

2. Is executableURL suitable to get the URL to a flat-file (non-bundled) application? Or is it only intended to get the executable inside of an application bundle? I have always assumed the former, because NSRunningApplication handles LSUIElement and LSBackgroundOnly applications as well as ordinary foreground applications, but the reference document doesn't say and I can't find any discussion.

3. Are there any flat-file (non-bundled) applications out there any longer? I think I've noticed some in the System folder.

--

Bill Cheeseman - email@hidden

_______________________________________________

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


  • Follow-Ups:
    • Re: NSRunningApplication executableURL issue in Swift
      • From: Roland King <email@hidden>
  • Prev by Date: Re: disabling Apple Crash Reporter
  • Next by Date: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • Previous by thread: MacOSX screensaver not loading due to Library not loaded: @rpath/libswiftAppKit.dylib
  • Next by thread: Re: NSRunningApplication executableURL issue in Swift
  • Index(es):
    • Date
    • Thread