Created
July 23, 2017 20:48
-
-
Save AlexZverusha/ca8142664f1aa595c7441b0cf97d213f to your computer and use it in GitHub Desktop.
Phantom types (Swift)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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