-1

Basically, I have a chat room in an iphone app and I want to block inappropriate words from it. I have an array of these words called blackList. However, whenever I run the code below, I get the error that "use of undeclared identifier 'foundRange'" and the warning that "incompatible pointer types passing NSString to parameter of type 'CFStringRef (aka 'const struct _ CFString". What is the problem? Please provide code in your answer.Here is my code:

- (void)displayChatMessage:(NSString*)message fromUser:(NSString*)userName {

    int i=0;

    for (i=0; i<[blackList count] ; i++){

        NSString *one = [NSString stringWithFormat:@"%@",[blackList objectAtIndex:i]];

        if (CFStringFindWithOptions(message,one , CFRangeMake(0,CFStringGetLength(message)), kCFCompareCaseInsensitive, &foundRange) == true) {
           /*do nothing*/
        }

        else {

            [chat appendTextAfterLinebreak:[NSString stringWithFormat:@"%@: %@", userName, message]];
        [chat scrollToBottom:chat];

        }


    }





}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2779450
  • 733
  • 1
  • 9
  • 19
  • First of all, from where is `foundRange`? Where is it declared? Then, you're using `CFStringRef` fonction with an object `NSString`. So what do you expect if you don't put the right parameters. Of course, there is bridge between `CFStringRef` & `NSString`, but you could look a little. – Larme Apr 19 '14 at 22:05
  • Also, note that this is a bad way to do what you're trying to do. For example, if the word "ass" is in your list, you'll block legitimate words like "classic" and users won't understand why. – user1118321 Apr 19 '14 at 22:12
  • http://en.wikipedia.org/wiki/Scunthorpe_problem – jrturton Apr 19 '14 at 22:16

1 Answers1

0

NSString and CFString support Toll-free bridging, which means they can be used interchangeably. But when Automatic Reference Counting came along a few years ago, things were tweaked a little bit. ARC doesn't manage Core Foundation objects because they are C, and not Objective-C. So you have to determine what you want the ownership semantics to be. You can probably get away with casting as __bridge.

For more, read up on this - https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677

bpapa
  • 21,409
  • 25
  • 99
  • 147