Está funcionando para NSString
que você possa usá-lo assim:
extension String {
func stringByAppendingPathComponent(path: String) -> String {
let nsSt = self as NSString
return nsSt.stringByAppendingPathComponent(path)
}
}
Agora você pode usar esta extensão que irá converter o seu String
em NSString
primeiro e depois executar a operação.
E seu código será:
let writePath = NSTemporaryDirectory().stringByAppendingPathComponent("instagram.igo")
Aqui estão alguns outros métodos para uso:
extension String {
var lastPathComponent: String {
return (self as NSString).lastPathComponent
}
var pathExtension: String {
return (self as NSString).pathExtension
}
var stringByDeletingLastPathComponent: String {
return (self as NSString).stringByDeletingLastPathComponent
}
var stringByDeletingPathExtension: String {
return (self as NSString).stringByDeletingPathExtension
}
var pathComponents: [String] {
return (self as NSString).pathComponents
}
func stringByAppendingPathComponent(path: String) -> String {
let nsSt = self as NSString
return nsSt.stringByAppendingPathComponent(path)
}
func stringByAppendingPathExtension(ext: String) -> String? {
let nsSt = self as NSString
return nsSt.stringByAppendingPathExtension(ext)
}
}
Referência AQUI .
Para o Swift 3.0:
extension String {
func stringByAppendingPathComponent1(path: String) -> String {
let nsSt = self as NSString
return nsSt.appendingPathComponent(path)
}
}
let writePath = NSTemporaryDirectory().stringByAppendingPathComponent(path: "instagram.igo")
extension String {
var lastPathComponent: String {
return (self as NSString).lastPathComponent
}
var pathExtension: String {
return (self as NSString).pathExtension
}
var stringByDeletingLastPathComponent: String {
return (self as NSString).deletingLastPathComponent
}
var stringByDeletingPathExtension: String {
return (self as NSString).deletingPathExtension
}
var pathComponents: [String] {
return (self as NSString).pathComponents
}
func stringByAppendingPathComponent(path: String) -> String {
let nsSt = self as NSString
return nsSt.appendingPathComponent(path)
}
func stringByAppendingPathExtension(ext: String) -> String? {
let nsSt = self as NSString
return nsSt.appendingPathExtension(ext)
}
}
Application%20Support