This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dropbox.android.sample; | |
import android.os.AsyncTask; | |
import android.util.Log; | |
import com.dropbox.client.DropboxAPI; | |
public class LoginAsyncTask extends AsyncTask<Void, Void, Integer> { | |
private static final String TAG = "LoginAsyncTask"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//String extension that checks for an empty (after trimming whitespace) or nil string: | |
// | |
// Usage: var isEmpty = String.isNilOrEmpty(myString) | |
// | |
// Credit to: Kevin McNeish | |
// http://iosappsfornonprogrammers.com/forum/index.php?topic=1836.0 | |
extension String { | |
public static func isNilOrEmpty(string: String?) -> Bool { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Double { | |
var second: NSTimeInterval { return self } | |
var seconds: NSTimeInterval { return self } | |
var minute: NSTimeInterval { return self * 60 } | |
var minutes: NSTimeInterval { return self * 60 } | |
var hour: NSTimeInterval { return self * 3600 } | |
var hours: NSTimeInterval { return self * 3600 } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
func combine(separator: String) -> String{ | |
var str : String = "" | |
for (idx, item) in enumerate(self) { | |
str += "\(item)" | |
if idx < self.count-1 { | |
str += separator | |
} | |
} | |
return str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func log(message: String) { | |
let thread = Thread.current.isMainThread ? "Main" : "Background" | |
print("\(thread) thread: \(message)") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String { | |
var isValidEmail: Bool { | |
let emailFormat = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | |
let emailPredicate = NSPredicate(format:"SELF MATCHES %@", emailFormat) | |
return emailPredicate.evaluate(with: self) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
class Alert { | |
class func showBasic(title: String, message: String, vc: UIViewController) { | |
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) | |
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) | |
vc.present(alert, animated: true) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class TaskManager { | |
static let shared = TaskManager() | |
let session = URLSession(configuration: .default) | |
typealias completionHandler = (Data?, URLResponse?, Error?) -> Void | |
var tasks = [URL: [completionHandler]]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomTextFieldWithPadding: UITextField { | |
let padding: CGFloat = 16 | |
private var paddingEdgeInsets: UIEdgeInsets { | |
return UIEdgeInsetsMake(0, padding, 0, padding) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SystemConfiguration.CaptiveNetwork | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
print("SSID: \(currentID(for: kCNNetworkInfoKeySSID))\nBSSID: \(currentID(for: kCNNetworkInfoKeyBSSID))") | |
} |
OlderNewer