Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
March 16, 2018, 09:22:56 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
Author Topic: Where to put categories?  (Read 2065 times)
Posts: 12

« on: September 01, 2009, 04:08:59 AM »

In the section about categories it is explained that:
It also gives you an easy way to extend an existing class definition without even having access to the original source code for the class and without having to create a subclass.

So there are cases that I can't put it in the original class. I also don't want to clutter my main.m file. Where then do I put that @interface and @implementation code of my category?

If I create a new file and put the category code in there, it effectively is a new class, isn't it?

Please, illuminate me Obi-Wan...
Hero Member
Posts: 3114

« Reply #1 on: September 01, 2009, 09:05:25 AM »

You can put it in the original class files if you want.  You can put the category into separate .h and .m files.  If you are working on a large project, for example, this allows you to divide the work of implementing a class and methods among several programmers.   Also, by restricting access to the category's .m file (where the code is), you can in a sense create "private" methods.

Remember that a category is an extension of the original class; it shares its instance variables and methods.  So that is quite different from defining a new class.


Steve Kochan
Pages: [1]   Go Up
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 All rights reserved.