Skip to content

Instantly share code, notes, and snippets.

//1
let keychain = Keychain(server: domain, protocolType: .https).synchronizable(true)
let email = UserDefaults.standard.object(forKey: "account") as? String
//2
if let account = email, let password = try? keychain.get(account) {
return password
}else {
//3
let keychain = Keychain(server: domain, protocolType: .https).synchronizable(true)
let email = UserDefaults.standard.object(forKey: "account") as? String
if let account = email, let password = try? keychain.get(account) {
return password
}else {
keychain.getSharedPassword({ [weak self] (account, password, error) in
guard let account = account, let password = password else { return }
keychain[account] = password // save in local keychain
//
// SharedWebCredentialsManager.swift
// Keychain
//
// Created by Mohammad Alatrash on 6/14/18.
//
import Foundation
enum SharedWebCredentialsManagerError: Error {
@mohammad19991
mohammad19991 / swiftlint-original.sh
Created April 25, 2018 11:28
SwiftLint script which will show warnings and errors displayed in the IDE for every single file in the project.
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
@mohammad19991
mohammad19991 / swiftlint.sh
Last active April 25, 2018 11:26
swiftlint script to check modified or added files in git.
#if [ "${CONFIGURATION}" = "Debug" ]; then
if which swiftlint >/dev/null; then
count=0
for file_path in $(git diff --diff-filter=ACM --name-only | grep ".*.swift$"); do
export SCRIPT_INPUT_FILE_$count=$file_path
count=$((count + 1))
done
for file_path in $(git diff --cached --name-only --diff-filter=ACM | grep ".*.swift$"); do
// Original Source http://www.dotnetperls.com/rot13-swift
// Edited version
extension String {
func rot13() -> String {
// Empty character array.
var result = [Character]()
// Some ASCII constants.
+ (NSMutableURLRequest *)imageRequestWithURL:(NSURL *)url {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.cachePolicy = NSURLRequestReturnCacheDataElseLoad; // this will make sure the request always returns the cached image
request.HTTPShouldHandleCookies = NO;
request.HTTPShouldUsePipelining = YES;
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
return request;
}
//
// MKNavigationController.m
//
//
// Created by Mohammad Alatrash on 7/29/15.
// Copyright (c) 2015 MKALatrash. All rights reserved.
//
/// A UINavigationController subclass allowing the interactive pop gesture to be recognized when the navigation bar is hidden or a custom back button is used.
#import "MKNavigationController.h"