Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlexZverusha/ca8142664f1aa595c7441b0cf97d213f to your computer and use it in GitHub Desktop.
Save AlexZverusha/ca8142664f1aa595c7441b0cf97d213f to your computer and use it in GitHub Desktop.
Phantom types (Swift)
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let urlpath = Bundle.main.path(forResource: "Info", ofType: "plist")
let url = NSURL.fileURL(withPath: urlpath!)
let test = FileSysytemUrl(url as NSURL)
if (test == nil) {
print("is empty")
} else {
print("its ok")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
struct FileSysytemUrl {
let url: NSURL
init?(_ url: NSURL){
if !url.isFileURL {
return nil
}
self.url = url
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment