Welcome, Guest. Please login or register.
Did you miss your activation email?
July 27, 2016, 02:43:13 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Programming in Objective-C, 4th edition
| |-+ Chapter 11
| | |-+ Using Categories in separate files,
Pages: [1] Go Down
Author Topic: Using Categories in separate files, (Read 2161 times)
Posts: 4

on: January 16, 2012, 10:50:09 AM

You mentioned that you could append the categories to separate files - but that you didn't mention how to do it?

If you have files main, Fraction.h, Fraction.m, and want to place your categories in separate files, what should be the naming convention of them?

For instance, naming your file Fraction(MathOps).h is invalid, as the "(" ")" are replaced with underscores.  Telling us how to do this would be extremely helpful, otherwise I feel the concept of modularity, promoted in this chapter, is somewhat lost.

Posts: 27

Reply #1 on: January 16, 2012, 03:16:19 PM

As with most things in XCode, the program handles this for you: when you go to make a new category, it'll automatically ask you which class you're extending and create the appropriately named files for you. If you try this, you'll see the naming convention is:


So in that case, it'd be:

Last Edit: January 16, 2012, 03:18:18 PM by jgelling Logged
Hero Member
Posts: 3114

Reply #2 on: January 16, 2012, 10:31:26 PM

In the next revision I will be sure to make a note about using Xcode to add a category (which is a new feature in Xcode 4.2 that I missed).  You can name the files anything you want (e.g., FractionMathOps, Fraction+MathOps, etc.).  The + sign is the convention that Apple has chosen, but is just a convention and not a requirement.  BTW, I did point out the naming conventions in the note on page 224.


Posts: 5

Reply #3 on: September 30, 2014, 05:35:49 PM

It's actually quite easy.

Simply hit Command+N and it'll open a new obj-c file. Click on empty objective c file, then there's an option to choose category. Then name your category. After that it'll be saved to your original project and Xcode will actually show your two new files in this format: "NameOfClass+NameOfCategory.h" and the exact same thing but also in a .m file.
From there just remember to #import your NameOfClass+NameOfCategory.h in main.
Pages: [1] Go Up
Jump to:

Login with username, password and session length

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 (c) 2009 classroomM.com. All rights reserved.