Skip to content

Instantly share code, notes, and snippets.

@usagimaru
Created March 7, 2017 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usagimaru/ac2a73fc389944c3b6c988f8c409c3d1 to your computer and use it in GitHub Desktop.
Save usagimaru/ac2a73fc389944c3b6c988f8c409c3d1 to your computer and use it in GitHub Desktop.
IndexPathExtension.swift
import Foundation
extension IndexPath {
static func fromString(_ string: String) -> IndexPath? {
let strs = string.components(separatedBy: ",")
var indexPath = IndexPath.init()
for str in strs {
if let i = Int(str) {
indexPath.append(i)
}
}
return indexPath
}
func stringValue() -> String {
var str = ""
var i = startIndex
while i < endIndex {
if str.characters.count != 0 {
str += ","
}
str += "\(i)"
i = index(after: i)
}
return str
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment