Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum FileStatus {
- case hidden
- case opened
- case password
- }
- struct File {
- private var content: String
- private var access: FileStatus
- private var password: String?
- init(content: String, access: FileStatus, password: String?) {
- self.content = content
- self.access = access
- self.password = self.access == .opened ? nil : password
- }
- private var accessToFile: FileStatus {
- let fileType: FileStatus
- switch access {
- case .hidden:
- fileType = .hidden
- case .password:
- fileType = .password
- default:
- fileType = .opened
- }
- return fileType
- }
- func showContent(password: String?) -> String {
- let resultOfProcessing: String
- switch accessToFile {
- case .opened:
- resultOfProcessing = self.content
- case .hidden:
- resultOfProcessing = "No access. File is hidden"
- case .password:
- if password == self.password {
- resultOfProcessing = self.content
- } else {
- resultOfProcessing = "Wrong password"
- }
- }
- return resultOfProcessing
- }
- }
- var movie = File(content: "Columbia pictures presents....", access: .password, password: "543")
- print(movie.showContent(password: "123"))
- var picture = File(content: "Beautiful flowers", access: .opened, password: "322")
- print(picture.showContent(password: nil))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement