Uploaded image for project: 'Swift'
  1. Swift
  2. SR-5829

Different output in Foundation Linux versus Foundation OSx

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Foundation
    • Labels:
      None
    • Environment:

      Linux (Ubuntu)

      OSx

      Swift 3

      Description

      While working in a small routine for finding a common directory path, the same function generated distinct results when run in OSx (as opposed to Linux, my system). The SO question that revealed this issue is here

       

      The code:

       

       

      import Foundation
      func getPrefix(_ text:[String]) -> String? {
      var common:String = text[0]
      for i in text {
      common = i.commonPrefix(with: common)
      } return common 
      }
      var test = ["/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator", "/home/user1/tmp/coven/members"]
      var output:String = getPrefix(test)!
      print(output)
      

       

       

      Will generate the correct answer in Linux:

      /home/user1/tmp

      But a wrong result in OSx:

      /home/user1/tmp/cove

      Screenshots of the two results can be found in the SO discussion in the link above.

        Attachments

        1. download.png
          download.png
          35 kB
        2. q3e1orx.png
          q3e1orx.png
          35 kB

          Activity

            People

            Assignee:
            spevans Simon Evans
            Reporter:
            lf-araujo Luis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: