Вы можете рассмотреть возможность использования NSMutableDictionary
и NSKeyedUnarchiver
следующим образом:
// Example ciphertext and salt
NSString *ciphertext = @"the ciphertext";
NSString *salt = @"the salt";
// File destination
NSString *path = @"/Users/Anne/Desktop/Archive.dat";
// Create dictionary with ciphertext and salt
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:ciphertext forKey:@"ciphertext"];
[dictionary setObject:salt forKey:@"salt"];
// Archive dictionary and write to file
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dictionary];
[data writeToFile:path options:NSDataWritingAtomic error:nil];
// Read file and unarchive
NSMutableDictionary *theDictionary = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
// Get ciphertext and salt
NSString *theCiphertext = [theDictionary objectForKey:@"ciphertext"];
NSString *theSalt = [theDictionary objectForKey:@"salt"];
// Show Result
NSLog(@"Extracted ciphertext: %@",theCiphertext);
NSLog(@"Extracted salt: %@",theSalt);
Выход:
Extracted ciphertext: the ciphertext
Extracted salt: the salt
EDIT
Ответ на комментарий: NSData
и NSString
функция length
.
Быстрый пример:
NSString *theString = @"Example String";
NSData *theData = [theString dataUsingEncoding:NSUTF8StringEncoding];
NSUInteger stringLength = [theString length];
NSUInteger dataLength = [theData length];
NSLog(@"String length: %ld",stringLength);
NSLog(@"Data length: %ld",dataLength);
Выход:
String length: 14
Data length: 14