Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Code won't run, no known class method for selector alloc?

I'm using a newer version of X-Code then the tutorial. In the tutorial the .m and .h made was under Iphone, Cocoa, Objective C class, since I did not have that option in my menu I selected the next closest thing which was Cocoa Class with objective C as the language.

In the first Objective C tutorial the typed out code in the main looked like:

Sphere *ball=[[Sphere alloc] init];

My code isn't running and says the error is "No known class method for selector 'alloc'"

How can I get this code to run and am I creating the correct kind of .m and .h

(I've checked the rest of my code for errors)

7 Answers

Michael Liendo
Michael Liendo
15,326 Points

Hi there and welcome :)

Is there a reason you're using an older version of Xcode? If you're building an iPhone app, then you should be using the CocoaTouch framework and not Cocoa. Hope that helps, let me know if you need more assistance.

No, I'm using the newer version of Xcode, the tutorial is using the older version. I don't think it would be beneficial for me to revert back to an older version.

The options were not the same in my window as that of the tutorial. I selected the only Cocoa option available (which was yes, the CocoaTouch framework) and selected the language as Objective C. Where as in the tutorial he selected the Cocoa class and there was no language option.

Michael Liendo
Michael Liendo
15,326 Points

Oh I see, sorry for the mix up on the Xcode version. I'll look into it for you, what is the exact tutorial that you're on?

Michael Liendo
Michael Liendo
15,326 Points

hmmm...it worked for me. "no known class method.." essentially means that Xcode isn't recognizing your alloc method. In your .h file, have you made sure to subclass NSObject by putting Sphere: NSObject there? I'll attach my screenshots to make sure we're on the same page. Sorry for the long troubleshoot...I've been purely Swift for the past 7 months!

Michael Liendo
Michael Liendo
15,326 Points

Well I couldn't find an easy way to add photos :/ so I posted them on twitter for you :)

https://twitter.com/model3volution

thanks so much I got it all figured out!

thanks so much I got it all figured out!