Create Category Getting Error "cannot define category for Undefined class"
Asked Answered
C

2

5

enter image description here

I am facing a problem when i try to create 2 category of my OWN Simple Class ( Class name is Car). I created 2 Category for this class just for testing " Car+show.h" & "Car+Protected.h". I Just write very small methods in to all like NSLog something sting.

My Problem is that when i build application I am getting error into Category File " Can not define Category for Undefined Class Car". Please Suggest me where i am Wrong. enter image description here

Check answered 17/12, 2013 at 9:48 Comment(1)
iphone-obsessed.blogspot.in/2010/05/…Squamous
C
17

If you import the category header files into Car.h, and your category header files themselves import Car.h, then you have a circular import which is causing you your problems.

Categories are for adding functionality to a class or splitting an interface out across several headers. If you are importing your category headers into your main class header, this is defeating the point.

The category headers should only be included by files that need to use functionality defined in the category.

Coh answered 17/12, 2013 at 10:36 Comment(1)
Thanks for Your answer Jrturton. I have again a question Like such way<\n> I have subclass of Car class ( @interface SecondCar:Car). As I extend Car class by these 2 categories. Will that Subclass access all that methods which is define into that category without import those category files into Subclass ( SecondCar.m") .Check
C
0

I have solved my problem luck by chance. I really don't know actual fact about that. The point is that when i import that category files into Car.h file that time it's create error which i shared with you. But when i Import that same file only and only Car.m file it's work fine.

I really don't know why it's create error when i import that category files into .h file. Please explain why it's getting error?

Thanks Mukesh

Check answered 17/12, 2013 at 10:27 Comment(1)
oh, so @jrturton's answer should explain itRasure

© 2022 - 2024 — McMap. All rights reserved.