如何在 swift 中编写 SFHFKeychainUtils



如何在 swift 3.0 中编写此代码

-(void)keychainitems
{
 NSString *appidStr;
NSError *saveerror;
NSString *savedstring=[SFHFKeychainUtils getPasswordForUsername:@"vikramarka" andServiceName:@"com.vikram.vikramarka" error:&saveerror ];
NSString *tempuniqstr;
if (savedstring==nil || savedstring.length<1)
{
    NSUUID *uuid = [[NSUUID alloc] init];
    tempuniqstr=[uuid UUIDString];
[SFHFKeychainUtils storeUsername:@"vikramarka" andPassword:tempuniqstr forServiceName:@"com.vikram.vikramarka" updateExisting:YES error:&saveerror ];  
  appidStr = tempuniqstr;
else
{
    appidStr = savedstring;
}
func keychainitems() {
    var appidStr: String
    var saveerror: Error?
    let savedstring: String? = try? SFHFKeychainUtils.getPasswordForUsername("vikramarka", andServiceName: "com.vikram.vikramarka")
    var tempuniqstr: String
    if savedstring == nil || (savedstring?.characters.count ?? 0) < 1 {
        let uuid = UUID()
        tempuniqstr = uuid.uuidString
        try? SFHFKeychainUtils.storeUsername("vikramarka", andPassword: tempuniqstr, forServiceName: "com.vikram.vikramarka", updateExisting: true)
        appidStr = tempuniqstr
    }
    else {
        appidStr = savedstring
    }
}

使用此实用程序将未来的目标 C 代码转换为 swift 3

相关内容

  • 没有找到相关文章

最新更新