am I DECLAREing wrong?

Coding Questions, IDE related or anything else

am I DECLAREing wrong?

Postby udo.killermann » Sat Apr 17, 2010 11:41 am

I want to initialize a data instance from an URL an am trying so, by declaring some support methods. The class and instance methods are directly taken from Apple's class references.
Code: Select all
Declare Function "NSData" - (id)initWithContentsOfURL:(NSURL *)aURL
Declare Function "NSData" + (id)data
Declare Function "NSData" + (id)dataWithContentsOfURL:(NSURL *)aURL
Declare Function "NSData" + (id)dataWithData:(NSData *)aData

Declare Class "NSURL"
Declare Function "NSURL" + (NSURL *)URLWithString:(NSString *)URLString
Declare Function "NSURL" - (BOOL)isFileURL
Declare Function "NSURL" - (NSString *)relativePath
Declare Function "NSURL" - (NSArray *)pathComponents

Event AwakeFromNib()
  Dim myURL As NSURL
  Dim myData As NSData
  Dim myData2 As NSData
  Dim myArray As Array

  Log("AwakeFromNib") 
  ' myURL stuff compiles and works like expected
  myURL = NSURL.URLWithString("http://www.heise.de/")
  Log(myURL)
  Log(myURL.isFileURL())
  Log(myURL.relativePath())
  myArray=myURL.pathComponents()
  ' myData=NSData.data() ' <- this works (compiles and runs correctly)
  myData=NSData.dataWithContentsOfURL(myURL) ' <- this fails (doesn't even compile)
 
  myData2=NSData.dataWithData(myData) ' <- this works, when using myData=NSData.data() (see above)
  Log(myData)
  Log(myData2)
  Log(myArray)

 
End Event

When trying to compile this code the compiler throws an error:
declareError.tiff
declareError.tiff (53.77 KiB) Viewed 1999 times


What am I doing wrong?

Thanks for your answer
Udo
--------------
MacBook (2GHz, 4 GByte) - Lion (10.7.3)
started Objective Basic coding in April 2010 - still enjoy it ;-)
udo.killermann
 
Posts: 247
Joined: Thu Apr 08, 2010 6:46 am
Location: Hannover, Germany

Re: am I DECLAREing wrong?

Postby berndnoetscher » Mon Apr 19, 2010 12:44 pm

Thanks for your help :-)
There seems to be a problem with arguments of non built-in types in ObjB yet (here it is NSURL) used in declare statements. You can workaround it by using type "id" instead NSURL and it will work as in the following code. Will add a fix to the next release coming the next days. The new version will be uploaded today.

By the way it is possible to load text from a website by using ReadString(...)

Code: Select all
''Declare Function "NSData" - (id)initWithContentsOfURL:(NSURL *)aURL
'Declare Function "NSData" + (id)data
Declare Function "NSData" + (id)dataWithContentsOfURL:(id)aURL
'Declare Function "NSData" + (id)dataWithContentsOfURL:(NSURL *)aURL
'Declare Function "NSData" + (id)dataWithData:(NSData *)aData

Declare Class "NSURL"
Declare Function "NSURL" + (NSURL *)URLWithString:(NSString *)URLString
Declare Function "NSURL" - (BOOL)isFileURL
Declare Function "NSURL" - (NSString *)relativePath
Declare Function "NSURL" - (NSArray *)pathComponents

Event AwakeFromNib()
  Dim myURL As NSURL
  Dim myData As NSData
  Dim myData2 As NSData
  Dim myArray As Array

 ' Log("AwakeFromNib") 
  ' myURL stuff compiles and works like expected
  myURL = NSURL.URLWithString("http://www.heise.de/")
  Log(myURL)
  Log(myURL.isFileURL())
  Log(myURL.relativePath())
  Log(myURL.pathComponents())
 
 
  Dim mm = myURL
  myData = NSData.dataWithContentsOfURL(mm)
  Alert(myData)
 
'  ' myData=NSData.data() ' <- this works (compiles and runs correctly)
'  myData=NSData.dataWithContentsOfURL(myURL) ' <- this fails (doesn't even compile)

'  myData2=NSData.dataWithData(myData) ' <- this works, when using myData=NSData.data() (see above)
'  Log(myData)
'  Log(myData2)
'  Log(myArray)

 
End Event
berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am

Re: am I DECLAREing wrong?

Postby udo.killermann » Mon Apr 19, 2010 7:42 pm

Bernd,

thanks for your hint. I had the impression it had to do with the class in question. When looking at your transpiled Objective-C code I saw the casting from and to NSObject. If the argument class has an initializer without parameters it seemed to work - not so if there is no such thing. But this doesn't seem to be the right direction. So your tip gets me working again.
BTW: I saw the NSString method to read from an URL, but wanted to test the thing by extending the NSData class.

Kind regards,
Udo
--------------
MacBook (2GHz, 4 GByte) - Lion (10.7.3)
started Objective Basic coding in April 2010 - still enjoy it ;-)
udo.killermann
 
Posts: 247
Joined: Thu Apr 08, 2010 6:46 am
Location: Hannover, Germany

Re: am I DECLAREing wrong?

Postby udo.killermann » Tue Apr 20, 2010 7:03 am

How would I handle
Code: Select all
(NSError **)theError
within a Declare? And how would I use it in my code? As I understand every pointer to a type (e.g. NSPoint *) in Objective-C is translated to a plain type (e.g. NSPoint) in Objective-Basic. Is there a way to declare this pointer-to-pointer construct used in some OC methods? Or is there another way to get the error information?
One such method is
Code: Select all
+ (id)dataWithContentsOfFile:(NSString *)path options:(NSDataReadingOptions)mask  error:(NSError **)errorPtr


Regards
Udo
--------------
MacBook (2GHz, 4 GByte) - Lion (10.7.3)
started Objective Basic coding in April 2010 - still enjoy it ;-)
udo.killermann
 
Posts: 247
Joined: Thu Apr 08, 2010 6:46 am
Location: Hannover, Germany

Re: am I DECLAREing wrong?

Postby berndnoetscher » Wed Apr 21, 2010 7:57 am

Using ** like (NSError **) is not possible yet, but I think it is important. So I added it to the todo list and hope to have it by the end of April 2010 done.
Please be patient.
berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am


Return to Objective-Basic (Xcode 3)

Who is online

Users browsing this forum: No registered users and 0 guests