Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
September 20, 2018, 12:30:15 AM *
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
  Print  
Author Topic: Category in Library  (Read 1855 times)
rhildreth
Newbie
*
Posts: 4


« on: September 13, 2011, 09:44:50 AM »

I've placed the MathOps category from Program 11.1 in its own files (Fraction+MathOps.h & .m) which works fine but the compiler complains that it can't find the methods (add:, etc.) unless I import Fraction+MathOps. On p. 224 is this:  "If you don’t have the capability to modify the
original header file directly (consider adding a category to an existing class from a
library, as shown in Part II,“The Foundation Framework”),".    I can't seem to find an explanation on how to add a category to an existing class from a library.

Anyone have some suggestions on how to do this?

Thanks.
Ron
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #1 on: September 13, 2011, 10:16:12 AM »

Ron,

It's easy to add a category to an existing class.  Just import Foundation.h and then add your class extension.  For example:

Code: (Objective-C)
#import <Foundation/Foundation.h>

@interface NSString (customPaths)
...
@end

adds a category called customPaths to the NSString class.   See page 360 for an example of how a category called Printing is added to the NSSet class.

Cheers,

Steve
Logged
rhildreth
Newbie
*
Posts: 4


« Reply #2 on: September 13, 2011, 08:22:38 PM »

Thanks - I understand that.

It's the "adding a category to an existing class from a library" procedure that I was looking for.

Ron
Logged
Pages: [1]   Go Up
  Print  
 
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 classroomM.com. All rights reserved.