Why Doesn't The Attached Program Compile?

Coding Questions, IDE related or anything else

Why Doesn't The Attached Program Compile?

Postby dekiefer » Thu Aug 26, 2010 8:39 am

Hi,

I'm having trouble getting OB to accept the NSImage function TIFFRepresentation. I'm sure I'm missing something in the definition or the declaration but, for the life of me, I can't figure it out. An example of the problem is attached.

I'll appreciate any suggestions,

Duane
Attachments
TestTIFF.zip
Project which demonstrates the TIFFRepresentation problem.
(33.17 KiB) Downloaded 119 times
dekiefer
 
Posts: 27
Joined: Tue Apr 20, 2010 11:51 pm

Re: Why Doesn't The Attached Program Compile?

Postby berndnoetscher » Thu Aug 26, 2010 11:04 am

You have an error in your code.

Code: Select all

 Dim mydata2myTiff As NSImage = myData.TIFFRepresentation()


Cannot work, because myData is of type NSData and TIFFRepresentation has been correctly declared for a NSImage.

If you want to set your NSImage from NSData use the code below.

Code: Select all

'above:
Declare Function "NSImage" + (id) alloc

'in init:

Dim mydata2myTiff As NSImage = NSImage.alloc()

mydata2myTiff.initWithData(myData)
berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am

Re: Why Doesn't The Attached Program Compile?

Postby dekiefer » Thu Aug 26, 2010 11:13 pm

Bernd,

Thanks for the coding pointers. I like your method of teaching.

Here's how I got your suggestion to work:

----------------------------->
'above added:
Declare Function "NSImage" - (id)initWithData:(NSData *)data

'in init changed your suggestion:
'mydata2myTiff.initWithData(myData)
'to:
mydata2myTiff = NSImage.initWithData(myData)

'and then this works
mydata2myTiff.TIFFRepresentation()

<-------------------------------------------------

Thank you for taking the time to help me.

Duane
dekiefer
 
Posts: 27
Joined: Tue Apr 20, 2010 11:51 pm

Re: Why Doesn't The Attached Program Compile?

Postby dekiefer » Fri Aug 27, 2010 7:06 am

Bernd,

The TestTIFF program compiles but when it's Run it throws the Exception: NSInvalidArgument Exception: +[NSImage initWithData:]: unrecognized selector sent to class.

I should have run it before I responded.

I've attached the Project when generates the exception.

I'd appreciate any guidance you might offer.

Duane
Attachments
TestTIFFException.zip
Demonstrates program which compiles but does not run.
(237.61 KiB) Downloaded 102 times
dekiefer
 
Posts: 27
Joined: Tue Apr 20, 2010 11:51 pm

Re: Why Doesn't The Attached Program Compile?

Postby berndnoetscher » Fri Aug 27, 2010 7:31 am

dekiefer wrote:Bernd,

The TestTIFF program compiles but when it's Run it throws the Exception: NSInvalidArgument Exception: +[NSImage initWithData:]: unrecognized selector sent to class.

I should have run it before I responded.

I've attached the Project when generates the exception.

I'd appreciate any guidance you might offer.

Duane


What happens with my code? Your new code cannot work, because you mix class and instance methods.
berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am

Re: Why Doesn't The Attached Program Compile?

Postby dekiefer » Fri Aug 27, 2010 6:13 pm

berndnoetscher wrote:
dekiefer wrote:Bernd,

The TestTIFF program compiles but when it's Run it throws the Exception: NSInvalidArgument Exception: +[NSImage initWithData:]: unrecognized selector sent to class.

I should have run it before I responded.

I've attached the Project which generates the exception.

I'd appreciate any guidance you might offer.

Duane


What happens with my code? Your new code cannot work, because you mix class and instance methods.


The changes you suggested wouldn't compile. As I pointed out in my response:
'in init changed your suggestion:
'mydata2myTiff.initWithData(myData) <-- Your suggestion wouldn't compile
'to:
mydata2myTiff = NSImage.initWithData(myData) <-- So I changed it to this

Duane
dekiefer
 
Posts: 27
Joined: Tue Apr 20, 2010 11:51 pm

Re: Why Doesn't The Attached Program Compile?

Postby dekiefer » Sat Aug 28, 2010 8:58 pm

Your new code cannot work, because you mix class and instance methods.


Please explain what you mean. Here's what the developer documentation says about 'NSImage initWithData':
---------------------------------------->>>
initWithData:
Initializes and returns an NSImage instance with the contents of the specified NSData object.

- (id)initWithData:(NSData *)data

Parameters
data -- The data object containing the image data.

Return Value -- An initialized NSImage instance, or nil if the method cannot create an image representation from the contents of the specified data object.

Availability -- Available in Mac OS X v10.0 and later.

Declared In NSImage.h
<<<--------------------
Does this not indicate that NSImage is to be initialized with NSData?
dekiefer
 
Posts: 27
Joined: Tue Apr 20, 2010 11:51 pm

Re: Why Doesn't The Attached Program Compile?

Postby berndnoetscher » Mon Aug 30, 2010 10:31 am

<<Does this not indicate that NSImage is to be initialized with NSData?

Yes.

Again watch out your declare statements
a + declares a class method
a - declares an instance method of an object

you mix it in your code.
Code: Select all
Declare Class "NSURL"
Declare Function "NSURL" + (id)URLWithString:(NSString *)URLString

Declare Function "NSData" + (id)dataWithContentsOfURL:(NSURL *)aURL

Declare Function "NSImage" - (id)initWithData:(NSData *)Data

Declare Function "NSImage" + (id) alloc


Event AwakeFromNib()
  Dim myData As NSData
  Dim myURL As NSURL
  Dim gifURL As String

  gifURL = "http://www.gifs.net/Animation11/Animals/Bears_and_Pandas/American_bear.gif" 
  myURL = NSURL.URLWithString(gifURL)

  myData = NSData.dataWithContentsOfURL(myURL)

Dim mydata2myTiff As NSImage = NSImage.alloc()

mydata2myTiff.initWithData(myData)
 


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

Re: Why Doesn't The Attached Program Compile?

Postby dekiefer » Mon Aug 30, 2010 9:55 pm

Thank you Bernd!

I appreciate your patience,

Duane
dekiefer
 
Posts: 27
Joined: Tue Apr 20, 2010 11:51 pm


Return to Objective-Basic (Xcode 3)

Who is online

Users browsing this forum: No registered users and 0 guests

cron