//
//  Runtime.swift
//  OpenSim
//
//  Created by Luo Sheng on 11/12/15.
//  Copyright © 2015 Luo Sheng. All rights reserved.
//

import Foundation

struct Runtime: CustomStringConvertible {
    
    let name: String
    
    var description: String {
        // current version is format "iOS major.minir"
        // old versions of iOS are com.Apple.CoreSimulator.SimRuntime.iOS-major-minor
        
        let characterSet = NSCharacterSet(charactersInString: " -.")
        let components = name.componentsSeparatedByCharactersInSet(characterSet)
        
        guard components.count > 2 else {
            return name
        }
        
        let lastTwoComponents = components[components.count - 2 ..< components.count]
        return lastTwoComponents.joinWithSeparator(".")
    }
    
    init(name: String) {
        self.name = name
    }
    
}
//
//  Runtime.swift
//  OpenSim
//
//  Created by Luo Sheng on 11/12/15.
//  Copyright © 2015 Luo Sheng. All rights reserved.
//

import Foundation

struct Runtime: CustomStringConvertible {
    
    let name: String
    
    var description: String {
        // current version is format "iOS major.minir"
        // old versions of iOS are com.Apple.CoreSimulator.SimRuntime.iOS-major-minor
        
        // current version, parse out iOS
        if name.hasPrefix("iOS ") {
            let index = name.startIndex.advancedBy(4)
            return name.substringFromIndex(index)
        }
        
        // older version parsing
        if let components = name.componentsSeparatedByString(".").last?.componentsSeparatedByString("-") {
            return components[1..<components.count].joinWithSeparator(".")
        }

        return name
    }
    
    init(name: String) {
        self.name = name
    }
    
}
--- 
+++ 
@@ -16,18 +16,15 @@
         // current version is format "iOS major.minir"
         // old versions of iOS are com.Apple.CoreSimulator.SimRuntime.iOS-major-minor
         
-        // current version, parse out iOS
-        if name.hasPrefix("iOS ") {
-            let index = name.startIndex.advancedBy(4)
-            return name.substringFromIndex(index)
+        let characterSet = NSCharacterSet(charactersInString: " -.")
+        let components = name.componentsSeparatedByCharactersInSet(characterSet)
+        
+        guard components.count > 2 else {
+            return name
         }
         
-        // older version parsing
-        if let components = name.componentsSeparatedByString(".").last?.componentsSeparatedByString("-") {
-            return components[1..<components.count].joinWithSeparator(".")
-        }
-
-        return name
+        let lastTwoComponents = components[components.count - 2 ..< components.count]
+        return lastTwoComponents.joinWithSeparator(".")
     }
     
     init(name: String) {
Use uniformed method to parse versions.
