Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Objective-c > I must be missi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 40 Topic 980 of 1009
Post > Topic >>

I must be missing something... (Categories)

by Don Bruder <dakidd@[EMAIL PROTECTED] > May 13, 2008 at 08:37 AM

Reading through the Objective C docs from Apple, I'm seeing this 
neat-sounding thing called "categories", whereby one can extend existing 
objects.

So, since I'm working with a wad of raw data (held by an NSMutableData 
object) that needs to do many searches for "magic strings" in the wad to 
locate the bits of data that it's actually interested in, I figured 
"This is a good place to do some extending".

I came up with the following. Apologies for blown line-wrapping - pasted 
directly from XCode, complete with my attempts at figuring out what's 
going wrong via printf(). And yes, I'm aware it's crude, clunky, and has 
its own built-in problem - as noted in the comment. If you'd be so kind 
as to ignore those details and concentrate on helping me figure out why 
it isn't working *AT ALL* (not even incorrectly...) I'd appreciate it:

-=-=-=- begin .h file
#im****t <Cocoa/Cocoa.h>

@[EMAIL PROTECTED]
 NSMutableData (Search)
- (unsigned)findNSString:(NSString *)targetString 
startingAt:(unsigned)Start;
@[EMAIL PROTECTED]
 end .h file

-=-=-=-- begin .m file
#im****t "NSMutableDataSearch.h"

// Extending NSMutableData by adding a crude findString:startingAt 
routine for NSMutableData objects.
// Takes an NSString (the target) and a starting location (offset from 
the start of the NSMutableData buffer). 
// Returns 0 = Not found (or found at location 0! Small problem here!) 
or non-zero for found.
// Restrictions: Best bet is to avoid sending this message to an 
instance unless it's known that the target data WILL NOT be found at 
offset 0...

@[EMAIL PROTECTED]
 NSMutableData (Search)

- (unsigned)findNSString:(NSString *)targetString 
startingAt:(unsigned)Start
{
   unsigned Max;
   unsigned Index;
   NSString *TempString;
   char TempCString[255];

   printf("Entering findNSString\n");
   Max = [self length];
   Index = 0;
   
   printf("findNSString: TargetString = '%s', Max = %d\n", [targetString 
getCString:&TempCString[0]], Max);
   for (Index=Start;Index < Max;Index++)
    {
      TempString = [NSString stringWithCharacters:([self 
mutableBytes]+Index) length:[targetString length]];
      printf("Checking against '%s'...\n", [TempString 
getCString:&TempCString[0]]);
      if ([targetString isEqualTo:TempString])
       {
         printf("Got a match in findNSString!\n");
         break;
       }
      else
       {
         printf("No match in findNSString\n");
       }
    }
   if (Index < Max)
      return Index;
   else
      return 0;
}

@[EMAIL PROTECTED]
 end .m file


Looks OK "on paper", but doesn't operate *AT ALL* in reality - When 
called, it does *ABSOLUTELY NOTHING*. It's as if it doesn't exist at all 
- No printf output from any of the diagnostics, and the returned value 
is zero every time. Trying to "step into" it in the debugger does 
zip-ola - It's as if it's a null statement.

So it would appear that I'm doing something wrong, misunderstanding the 
use of categories, or some of both. 

Hints? Clarifications? Assistance?

-- 
Don Bruder - dakidd@[EMAIL PROTECTED]
 - If your "From:" address isn't on my
whitelist,
or the subject of the message doesn't contain the exact text
"PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without
my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd>
for more
info
 




 40 Posts in Topic:
I must be missing something... (Categories)
Don Bruder <dakidd@[EM  2008-05-13 08:37:26 
Re: I must be missing something... (Categories)
Tom Harrington <tph@[E  2008-05-13 10:18:36 
Re: I must be missing something... (Categories)
Gregory Weston <uce@[E  2008-05-13 13:44:52 
Re: I must be missing something... (Categories)
Don Bruder <dakidd@[EM  2008-05-13 11:10:55 
Re: I must be missing something... (Categories)
Gregory Weston <uce@[E  2008-05-13 13:44:44 
Re: I must be missing something... (Categories)
Don Bruder <dakidd@[EM  2008-05-13 11:36:45 
Re: I must be missing something... (Categories)
Gregory Weston <uce@[E  2008-05-13 15:28:22 
Re: I must be missing something... (Categories)
Gregory Weston <uce@[E  2008-05-13 15:41:52 
Re: I must be missing something... (Categories)
Don Bruder <dakidd@[EM  2008-05-13 14:54:17 
Re: I must be missing something... (Categories)
Gregory Weston <uce@[E  2008-05-13 18:04:18 
Re: I must be missing something... (Categories)
William Yeo <wcyeo@[EM  2008-05-13 15:14:21 
Re: I must be missing something... (Categories)
Don Bruder <dakidd@[EM  2008-05-13 16:02:00 
Re: I must be missing something... (Categories)
William Yeo <wcyeo@[EM  2008-05-13 16:41:09 
Re: I must be missing something... (Categories)
Don Bruder <dakidd@[EM  2008-05-13 18:15:56 
Re: I must be missing something... (Categories)
William Yeo <wcyeo@[EM  2008-05-13 21:38:25 
Re: I must be missing something... (Categories)
Gregory Weston <uce@[E  2008-05-14 07:28:07 
Questions about memory management (was Re: I must be missing som
Don Bruder <dakidd@[EM  2008-05-23 11:01:11 
Re: Questions about memory management (was Re: I must be missing
Gregory Weston <uce@[E  2008-05-23 17:22:47 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-23 20:20:10 
Re: Questions about memory management (was Re: I must be missing
William Yeo <wcyeo@[EM  2008-05-23 20:59:14 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-23 21:49:26 
Re: Questions about memory management (was Re: I must be missing
Gregory Weston <uce@[E  2008-05-24 09:01:37 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-24 22:06:12 
Re: Questions about memory management (was Re: I must be missing
Gregory Weston <uce@[E  2008-05-25 08:29:49 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-25 11:23:08 
Re: Questions about memory management
Sherman Pendley <spamt  2008-05-25 17:34:26 
Re: Questions about memory management (was Re: I must be missing
William Yeo <wcyeo@[EM  2008-05-24 13:11:43 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-24 22:20:17 
Re: Questions about memory management (was Re: I must be missing
William Yeo <wcyeo@[EM  2008-05-24 23:37:13 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-25 10:22:16 
Re: Questions about memory management (was Re: I must be missing
William Yeo <wcyeo@[EM  2008-05-25 10:59:31 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-25 11:43:32 
Re: Questions about memory management (was Re: I must be missing
Gregory Weston <uce@[E  2008-05-25 15:27:50 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-25 13:07:37 
Re: Questions about memory management (was Re: I must be missing
Gregory Weston <uce@[E  2008-05-26 07:30:16 
Re: Questions about memory management (was Re: I must be missing
Don Bruder <dakidd@[EM  2008-05-26 07:30:02 
Re: Questions about memory management (was Re: I must be missing
glenn andreas <gandrea  2008-05-25 18:53:55 
Re: Questions about memory management (was Re: I must be missing
Gregory Weston <uce@[E  2008-05-24 08:57:32 
Re: I must be missing something... (Categories)
Matthias Benkard <usen  2008-05-14 15:26:05 
Re: I must be missing something... (Categories)
Matthias Benkard <mulk  2008-05-13 12:20:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 18:19:05 CDT 2008.