1 Reply
      Latest reply: Nov 22, 2016 2:01 AM by eskimo RSS
      kakuen Level 1 Level 1 (0 points)

        It was like this in swift2.3 in GitHub

        "              self.ListGroupname = tempList.sortedArrayUsingSelector(Selector("compare:"))          "

         

         

        and the system of swift 3.0 convert it to

        "               self.listGroupname = tempList.sortedArray(using: "compare:")                                        "

         

        while it gives a error message "          sorted array produces [any] not the expected contextual result type "NSArray"    

         

         

         

        I have no idea what can I do. Can someone help?

        • Re: fail to convert sortedArrayfromUsingSelector from 2.3 to 3.0
          eskimo Apple Staff Apple Staff (7,960 points)

          It’s hard to be 100% sure what’s going on here without knowing the type of tempList and self.listGroupname but, presuming they’re both NSArray, the issue is that NSArray.sortedArray(using:) now returns [Any], which is not directly assignable to NSArray.  A quick fix would be to add an as NSArray.

          self.listGroupname = tempList.sortedArray(using: #selector(NSString.compare(_:))) as NSArray
          

          However, you’d be better off looking at your use of NSArray to see if you can make the jump to Swift arrays.  They have a bunch of advantages, not least of which is the thorough type checking.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"