Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 10th, 2020 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. enum FileStatus {
  2.  
  3.     case hidden
  4.     case opened
  5.     case password
  6. }
  7.  
  8. struct File {
  9.    
  10.     private var content: String
  11.     private var access: FileStatus
  12.     private var password: String?
  13.    
  14.     init(content: String, access: FileStatus, password: String?) {
  15.         self.content = content
  16.         self.access = access
  17.         self.password = self.access == .opened ? nil : password
  18.     }
  19.    
  20.     private var accessToFile: FileStatus {
  21.         let fileType: FileStatus
  22.         switch access {
  23.         case .hidden:
  24.             fileType = .hidden
  25.         case .password:
  26.             fileType = .password
  27.         default:
  28.             fileType = .opened
  29.         }
  30.         return fileType
  31.     }
  32.    
  33.     func showContent(password: String?) -> String {
  34.         let resultOfProcessing: String
  35.         switch accessToFile {
  36.         case .opened:
  37.             resultOfProcessing = self.content
  38.         case .hidden:
  39.             resultOfProcessing = "No access. File is hidden"
  40.         case .password:
  41.             if password == self.password {
  42.                 resultOfProcessing = self.content    
  43.             } else {
  44.                 resultOfProcessing = "Wrong password"
  45.             }    
  46.         }
  47.         return resultOfProcessing
  48.     }
  49.    
  50. }
  51.  
  52. var movie = File(content: "Columbia pictures presents....", access: .password, password: "543")
  53. print(movie.showContent(password: "123"))
  54.  
  55. var picture = File(content: "Beautiful flowers", access: .opened, password: "322")
  56. print(picture.showContent(password: nil))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top