Page 1 of 1

How to use setResourceValue:forKey:error:

Posted: Thu Sep 08, 2016 9:22 pm
by Wolfram
Can someone tell me what's wrong on this COCOA massage?

Code: Select all

fileURL = CocoaMessage(0, 0 ,"NSURL fileURLWithPath:$", @"/Users/yourName/Desktop/testFile.TXT")

Define *resourceError 
CocoaMessage(0, fileURL, "setResourceValue:", 2, "forKey:$", @"NSURLLabelNumberKey", "error:", @resourceError)

Re: How to use setResourceValue:forKey:error:

Posted: Fri Sep 09, 2016 5:28 am
by wilbert
I think the resource value 2 needs to be wrapped into a NSNumber.
Try to pass this instead of 2

Code: Select all

CocoaMessage(0, 0, "NSNumber numberWithInt:", 2)

Re: How to use setResourceValue:forKey:error:

Posted: Fri Sep 09, 2016 9:36 am
by Wolfram
wilbert wrote:I think the resource value 2 needs to be wrapped into a NSNumber.
Try to pass this instead of 2

Code: Select all

CocoaMessage(0, 0, "NSNumber numberWithInt:", 2)
You think right ;-)
Thanks

Re: How to use setResourceValue:forKey:error:

Posted: Fri Sep 09, 2016 10:32 am
by Wolfram
Last question…
can you tell me how to read the error state of this function?

Code: Select all

CocoaMessage(0, fileURL, "setResourceValue:", CocoaMessage(0, 0, "NSNumber numberWithInt:", 2), "forKey:$", @"NSURLLabelNumberKey", "error:", @resourceError)

Re: How to use setResourceValue:forKey:error:

Posted: Fri Sep 09, 2016 11:26 am
by wilbert
Wolfram wrote:can you tell me how to read the error state of this function?
It's a NSError object.

Code: Select all

Debug PeekS(CocoaMessage(0, CocoaMessage(0, resourceError, "localizedDescription"), "UTF8String"), -1, #PB_UTF8)

Re: How to use setResourceValue:forKey:error:

Posted: Fri Sep 09, 2016 11:58 am
by Wolfram
wilbert wrote:
Wolfram wrote:can you tell me how to read the error state of this function?
It's a NSError object.

Code: Select all

Debug PeekS(CocoaMessage(0, CocoaMessage(0, resourceError, "localizedDescription"), "UTF8String"), -1, #PB_UTF8)
I try this code, but get an error "Address is null".

Code: Select all


fileURL = CocoaMessage(0, 0 ,"NSURL fileURLWithPath:$", @"/Users/yourNmae/Desktop/testFile.txt")
Define resourceError
CocoaMessage(0, fileURL, "setResourceValue:", CocoaMessage(0, 0, "NSNumber numberWithInt:", 2), "forKey:$", @"NSURLLabelNumberKey", "error:", @resourceError)

Debug PeekS(CocoaMessage(0, CocoaMessage(0, resourceError, "localizedDescription"), "UTF8String"), -1, #PB_UTF8)

Re: How to use setResourceValue:forKey:error:

Posted: Fri Sep 09, 2016 12:23 pm
by wilbert
I forgot to wrap it.
It should only display the error is there is one.

Code: Select all

fileURL = CocoaMessage(0, 0 ,"NSURL fileURLWithPath:$", @"/Users/yourNmae/Desktop/testFile.txt")
If CocoaMessage(0, fileURL, "setResourceValue:", CocoaMessage(0, 0, "NSNumber numberWithInt:", 2), "forKey:$", @"NSURLLabelNumberKey", "error:", @resourceError) = #NO
  Debug PeekS(CocoaMessage(0, CocoaMessage(0, resourceError, "localizedDescription"), "UTF8String"), -1, #PB_UTF8)
EndIf