2016-11-16 3 views
0

빠른 3 내 코드를 변환 한 후 나는 오류를 받고 있어요 다른 설명없이 (lldb)라고 말하는 오류는 누구나 여기서 무엇이 잘못되었는지 설명 할 수 있습니까 ?? 및 변환하기 전에이 같았다 :빠른 3 변환의 원인 (lldb) 오류`EXC_BAD_INSTRUCTION (코드 = EXC_I386_INVOP, 서브 코드) = 0x0`

noteObjects.sortUsingComparator { (first : AnyObject, second : AnyObject) -> NSComparisonResult in 
     if let f : String = (first as! RChannels).name! { 
      let s : String = (second as! RChannels).name! 
      return f.compare(s) 
     } 
    } 

noteObjectsas! (Any, Any) -> ComparisonResult 제거하고 Any 대신 AnyObject에 두 개의 매개 변수를 변경 얻을 NSMutableArray를

+1

왜 까닭없는 비교기와 NSMutableArray? 기본 Swift 배열 유형 및 정렬 기능이 훨씬 효율적입니다. – vadian

답변

0

입니다.

noteObjects.sort(comparator: { (first : Any, second : Any) -> ComparisonResult in 
    if let f : String = (first as! RChannels).name! { 
     let s : String = (second as! RChannels).name! 

     return f.compare(s) 
    } 
}) 

하지만 여전히 몇 가지 문제가 있습니다. 모든 코드 경로에 대해 return 값이 없으며 선택 사항을 제대로 처리하지 못합니다. 다음은 더 좋을 것입니다 :

noteObjects.sort(comparator: { (first : Any, second : Any) -> ComparisonResult in 
    if let f = (first as! RChannels).name, let s = (second as! RChannels).name { 
     return f.compare(s) 
    } else { 
     return .orderedSame 
    } 
}) 
관련 문제