Skip to content

Instantly share code, notes, and snippets.

View akultomar17's full-sized avatar

Akul Tomar akultomar17

View GitHub Profile
private static void recurseOnFolder(File file) {
if (file.isFile() && file.getName().endsWith(".java")) {
if (!file.equals(new File("/Users/akultomar/Workspace/A_Shop101/O1Server/O1Server-model/src/main/java/com/localization/ErrorCodeConstants.java"))) {
replaceErrorCodes(file);
}
} else if (file.isDirectory()) {
File[] file1 = file.listFiles();
for(File file2: file1) {
recurseOnFolder(file2);
}
func getReadableDate(timeStamp: TimeInterval) -> String? {
let date = Date(timeIntervalSince1970: timeStamp)
let dateFormatter = DateFormatter()
if Calendar.current.isDateInTomorrow(date) {
return "Tomorrow"
} else if Calendar.current.isDateInYesterday(date) {
return "Yesterday"
} else if dateFallsInCurrentWeek(date: date) {
if Calendar.current.isDateInToday(date) {
func showError(error: LAError) {
var message: String = ""
switch error.code {
case LAError.authenticationFailed:
message = "Authentication was not successful because the user failed to provide valid credentials. Please enter password to login."
break
case LAError.userCancel:
message = "Authentication was canceled by the user"
break
case LAError.userFallback:
fileprivate func saveAccountDetailsToKeychain(account: String, password: String) {
guard account.isEmpty, password.isEmpty else { return }
UserDefaults.standard.set(account, forKey: "lastAccessedUserName")
let passwordItem = KeychainPasswordItem(service: KeychainConfiguration.serviceName, account: account, accessGroup: KeychainConfiguration.accessGroup)
do {
try passwordItem.savePassword(password)
} catch {
print("Error saving password")
}
}
fileprivate func loadPasswordFromKeychainAndAuthenticateUser(_ account: String) {
guard !account.isEmpty else { return }
let passwordItem = KeychainPasswordItem(service: KeychainConfiguration.serviceName, account: account, accessGroup: KeychainConfiguration.accessGroup)
do {
let storedPassword = try passwordItem.readPassword()
authenticateUser(storedPassword)
} catch KeychainPasswordItem.KeychainError.noPassword {
print("No saved password")
} catch {
print("Unhandled error")
func evaulateTocuhIdAuthenticity(context: LAContext) {
guard let lastAccessedUserName = UserDefaults.standard.object(forKey: "lastAccessedUserName") as? String else { return }
context.evaluatePolicy(LAPolicy.deviceOwnerAuthentication, localizedReason: lastAccessedUserName) { (authSuccessful, authError) in
if authSuccessful {
} else {
if let error = authError as? LAError {
showError(error: error)
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
authenticateUserUsingTouchId()
}
fileprivate func authenticateUserUsingTouchId() {
let context = LAContext()
if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthentication, error: nil) {
self.evaulateTocuhIdAuthenticity(context: context)
}