2014-04-19 7 views
-1

기본적으로 아이폰 앱에 대화방이있어서 부적절한 단어를 차단하고 싶습니다. blackList라는 단어가 있습니다. 그러나 아래 코드를 실행할 때마다 "use of undeclared identifier 'foundRange'"과 "incompatible pointer types passing NSString to parameter of type 'CFStringRef (aka 'const struct _ CFString"이라는 경고가 표시됩니다. 문제가 무엇입니까?채팅방의 부적절한 콘텐츠 차단하기

- (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]; 

     } 


    } 





} 
+0

첫째 - 자세한 내용은

이에 읽어? 선언 된 곳은 어디입니까? 그런 다음,'NSString' 객체와 함께'CFStringRef' 함수를 사용하고 있습니다. 올바른 매개 변수를 지정하지 않으면 무엇을 기대할 수 있습니까? 물론,'CFStringRef'와'NSString' 사이에 다리가 있습니다.하지만 약간 보일 수도 있습니다. – Larme

+0

또한이 작업은 수행하려는 작업을 수행하는 나쁜 방법이라는 점에 유의하십시오. 예를 들어 '엉덩이'라는 단어가 목록에 있으면 '고전적'과 같은 합법적 인 단어를 차단하므로 사용자가 그 이유를 이해하지 못합니다. – user1118321

+0

http://en.wikipedia.org/wiki/Scunthorpe_problem – jrturton

답변

0

있는 NSString 및 CFString 지원 수신자 부담 브리징, 그들은 상호 교환 사용할 수의 의미 : answer.Here 코드를 입력하십시오 나의 코드입니다. 그러나 Automatic Reference Counting이 몇 년 전 출시되었을 때 상황이 약간 변경되었습니다. ARC는 C가 아니고 Objective-C가 아니기 때문에 Core Foundation 객체를 관리하지 않습니다. 따라서 소유권 의미가 무엇인지 결정해야합니다. 아마도 __bridge로 캐스팅을 할 수 있습니다. `foundRange` 어디에서, 모든 https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677