Page 1 of 1

How to use pathForResource: ??

Posted: Sat Nov 26, 2016 7:12 pm
by Wolfram
Can some tell my what's wrong with this code?
I get the Error object is nil, but I think it does't need a object.

If you want to know what I'm trying to do: I want to get the path of the curser resource.

Code: Select all

 Path.s
CocoaMessage(@Path, 0, "pathForResource:$", @"cursor_1only_", "ofType:$", @"")
Debug Path

Re: How to use pathForResource: ??

Posted: Sun Nov 27, 2016 8:38 pm
by Shardik
You have to specify an NSBundle when calling method pathForResource:ofType:. Please take a look into the following working example which defines a bundle for TextEdit and displays the path to the file Edit.icns contained in TextEdit.app:

Code: Select all

; ----- Get NSBundle for TextEdit.app
TextEditBundle = CocoaMessage(0, 0,
  "NSBundle bundleWithPath:$", @"/Applications/TextEdit.app")

If TextEditBundle
  ; ----- Get path to file Edit.icns
  *Path = CocoaMessage(0, TextEditBundle,
    "pathForResource:$", @"Edit",
    "ofType:$", @"icns")
  Debug PeekS(CocoaMessage(0, *Path, "UTF8String"), -1, #PB_UTF8)
EndIf