Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 23, 2011, 03:49 PM   #1
galimk
macrumors newbie
 
Join Date: Apr 2011
Cannot use created class in the XCode?

Hello everyone,

I am new to Objectvice C and just started learning it.

The situation that I cannot resolve is pretty trivial, I am sure there is something simple I am missing. I created Fraction.m class in my test project in XCode using Source -> Add -> New File ->Objectvie C Class. I filled the .h file with the members and implemented all of them in the *m file. Afterwards I am trying to instantiate this Fraction class in my Program.h class in the main function.

I tried to include the .h file through #import <Fraction.h> directive but I get compiler error "No such file ore directory". Also whenever I am trying to use Fraction class, I get compiler error that Fraction is not defined. Though intellisense in the XCode code editor is seeing both "Fraction.h" and Fraction class. I am sure that there are no compilation errors in the Fraction.h and Fraction.m.

Thanks.
galimk is offline   0 Reply With Quote
Old Apr 23, 2011, 04:19 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by galimk View Post
I tried to include the .h file through #import <Fraction.h> directive but I get compiler error "No such file ore directory".
Look in your book for exactly what you're supposed to use for #import. You may have made a mistake.

I'm not sure, but #import <Fraction.h> seems wrong to me. If Fraction.h were a system-provided class, it would be correct. But it's a developer-created class, so #import "Fraction.h" seems more sensible to me, and is what I've always used when referring to class headers I create.


Quote:
I am sure that there are no compilation errors in the Fraction.h and Fraction.m.
Post your code.

No one with any programming experience would believe anyone (beginner or experienced) who says there are no compilation errors, unless the code has actually been compiled without errors. You may be right, but we need to see the evidence of the compiler.
chown33 is offline   0 Reply With Quote
Old Apr 23, 2011, 06:30 PM   #3
galimk
Thread Starter
macrumors newbie
 
Join Date: Apr 2011
Quote:
Originally Posted by chown33 View Post
Look in your book for exactly what you're supposed to use for #import. You may have made a mistake.

I'm not sure, but #import <Fraction.h> seems wrong to me. If Fraction.h were a system-provided class, it would be correct. But it's a developer-created class, so #import "Fraction.h" seems more sensible to me, and is what I've always used when referring to class headers I create.



Post your code.

No one with any programming experience would believe anyone (beginner or experienced) who says there are no compilation errors, unless the code has actually been compiled without errors. You may be right, but we need to see the evidence of the compiler.
Thanks! Your answer helped. So now I know that <**> are only for system provided classes. I used quotes for Fraction.h and it worked.
The example that I used had everything dumped in the main .m file along with the main function.
galimk is offline   0 Reply With Quote
Old Apr 23, 2011, 07:53 PM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by galimk View Post
Thanks! Your answer helped. So now I know that <**> are only for system provided classes. I used quotes for Fraction.h and it worked.
The example that I used had everything dumped in the main .m file along with the main function.
I'm glad you got it working, but please be specific in the future about what you did, and what the book told you to do. Accuracy is important in programming. Books are specific about what to do because the author knows what works and what doesn't, and has given accurate instructions on what to do that works.

If you're working from a book, and they show you what to put into a file, you should put exactly that into a file. So if your book showed you to put everything dumped into the main.m file, then that's what you should do.

However, if they showed you something else, then dumping everything into a single main.m file is asking for trouble, because you don't know all the consequences of what you're doing.

If the book showed "Fraction.h", then that's what you should use. If they showed <Fraction.h> and it didn't work, then that's an error in the book.

Do not make changes to what a book tells you unless you fully understand what the consequences are. And if you're a beginner, then almost by definition, a beginner does not fully understand all the consequences. If you did understand all the consequences, you wouldn't be a beginner.
chown33 is offline   0 Reply With Quote
Old Apr 23, 2011, 08:10 PM   #5
KnightWRX
macrumors Pentium
 
KnightWRX's Avatar
 
Join Date: Jan 2009
Location: Quebec, Canada
Quote:
Originally Posted by galimk View Post
Your answer helped. So now I know that <**> are only for system provided classes.
Actually, <include.h> is for headers that are found in the -I include paths specified in the CFLAGS var usually with make. You could add -I/path/to/your/headers to your GCC command line and then #include <yourheader.h> just like any other "system" include. #include "yourheader.h" includes headers either with an absolute or relative path to the current working directory of the compiler, which when using a make based system, happens to be your source directory.

Just some extra info there for you.
__________________
"What you leave behind is not what is engraved in stone monuments, but what is woven into the lives of others."
-- Pericles
KnightWRX is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
The Java class file "xxx.class" could not be launched. piratemacfan Mac Applications and Mac App Store 1 Aug 31, 2013 04:24 PM
The Java class file "PopSampleApplet.class" could not be launched. piratemacfan OS X 10.8 Mountain Lion 0 Aug 30, 2013 04:03 PM
Referencing a child class in a parent class, good or bad? SAIRUS iPhone/iPad Programming 11 Aug 28, 2013 12:59 PM
Xcode 4.5.1 and class extensions not enabled by default daproject85 iPhone/iPad Programming 2 Oct 14, 2012 03:22 AM
Difference between Public class and private class. zijianz iPhone/iPad Programming 4 Jun 29, 2012 10:29 PM

Forum Jump

All times are GMT -5. The time now is 12:43 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC