我正在尝试使用文本文件制作一个简单的受密码保护的应用程序来存储用户输入的密码。我想将文本字段中的内容存储在文件中,并最终将该文件中的内容与用户在另一个文本字段中输入的内容进行比较。这是我所拥有的:
//Setting the string to hold the password the user has entered
NSString *createPassword1 = passwordSet.text;
//creating a muttable array to store the value of createPassword1
NSMutableArray *passwordArray = [NSMutableArray array];
//storing createpassword1 into the first element of the array
[passwordArray addObject:createPassword1];
NSLog(@"%@",[passwordArray objectAtIndex:0]);//seeing if it is stored correctly (it is)
//path for searching for the file
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
//my filename
NSString *fileName = @"PasswordFile.txt";
NSString *fileAndPath = [path stringByAppendingPathComponent:fileName];
if (![[NSFileManager defaultManager] fileExistsAtPath:fileAndPath]) {
[[NSFileManager defaultManager] createFileAtPath:fileAndPath contents:nil attributes:nil];
}
[[[passwordArray objectAtIndex:0] dataUsingEncoding:NSUTF8StringEncoding] writeToFile:fileAndPath atomically:YES];
任何帮助将不胜感激,谢谢。