Programing/My OSS
[Swift] String test in PlayGround
나모찾기
2020. 10. 3. 12:10
xcode에는 PlayGround 라는 코드를 쉽게 테스트하기 위한 인터페이스를 제공한다.
REPL 이라는 말처럼 스크립트 언어를 쓰고 평가를 바로바로 해서 어떤 결과를 만드는지 확인할 수 있는 시스템(체계)이다.
import UIKit
import Foundation
// https://forums.swift.org/t/checking-if-a-url-is-a-directory/13842
// https://stackoverflow.com/questions/24208728/check-if-nsurl-is-a-directory
extension URL {
var isDirectory: Bool {
let values = try? resourceValues(forKeys: [.isDirectoryKey])
return values?.isDirectory ?? false
}
}
let url = URL(fileURLWithPath: "/Users/namo/Desktop/tube/babybus_45.mp4")
url.path
url.isFileURL
url.hasDirectoryPath
if (!url.isDirectory) {
url.path
type(of: url.path)
//url.path.substring(url.lastPathComponent)
}
let url2 = URL(fileURLWithPath: "/Users/namo/Desktop/tube")
url2.isFileURL
url2.hasDirectoryPath
url2.lastPathComponent
url2.isDirectory
var fullPath = "/Users/namo/Desktop/tube/babybus_45.mp4"
let lastPart = "babybus_45.mp4"
let range = fullPath.index(fullPath.endIndex, offsetBy: -lastPart.count)..<fullPath.endIndex
fullPath.removeSubrange(range)