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
// Create Record | |
let record = CKRecord(recordType: "Posting") | |
record["url"] = self.urlField.text! | |
record["name"] = self.nameField.text! | |
// Get Database | |
let container = CKContainer.defaultContainer() | |
let database = container.publicCloudDatabase |
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 loadJobs() { | |
let sharedDefaults = NSUserDefaults(suiteName: "group.ca.sundeepgupta.job") | |
if let jobs = sharedDefaults?.arrayForKey("jobs") as? [[String: String]] { | |
self.jobs = jobs | |
} else { | |
sharedDefaults?.setObject([], forKey: "jobs") | |
} | |
self.tableView.reloadData() | |
} |
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
function containsQuestion(message) { | |
return 1; | |
} | |
function containsYou(message) { | |
return 0; | |
} | |
function senderRelationshipType(message) { | |
return 2; |
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
'use strict'; | |
const HTTPS = require('https'); | |
const URL = require('url'); | |
const QueryString = require('querystring'); | |
module.exports = function() { | |
return { | |
postJSON: function(url, params) { | |
const data = JSON.stringify(params); |
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 | |
protocol Decodable { | |
func decode() -> Void | |
} | |
struct Action { | |
let decodable: AnyDecodable | |
} |
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 TheClass { | |
class func swizzle(_ original: Selector, with swizzled: Selector, for klass: AnyClass) { | |
let originalMethod = class_getInstanceMethod(klass, original) | |
let swizzledMethod = class_getInstanceMethod(klass, swizzled) | |
method_exchangeImplementations(originalMethod, swizzledMethod) | |
} | |
func swizzle(_ original: Selector, with swizzled: Selector) { | |
let klass: AnyClass! = object_getClass(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
class CoreGlobal { | |
fileprivate static let shared = CoreGlobal() | |
fileprivate let device: DeviceManager | |
private class Config { | |
var deviceManager: DeviceManager? | |
} | |
private static let config = Config() | |
@discardableResult |
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
let appDelegateClass: AnyClass? = NSClassFromString("TEST_TARGET_MODULE_NAME.TestAppDelegate") ?? AppDelegate.self | |
let classString = NSStringFromClass(appDelegateClass!) | |
let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv) | |
.bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)) | |
UIApplicationMain(CommandLine.argc, argv, nil, classString) |
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
let semaphore = DispatchSemaphore(value: 0) | |
asyncFunction() { result in | |
XCTAssert(result) | |
semaphore.signal | |
} | |
while semaphore.wait(timeout: .now()) == .timedOut { | |
RunLoop.current.run(until: Date(timeIntervalSinceNow: 3)) | |
} |
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 | |
// MARK: - Public | |
public struct WebService { | |
let actionManager: ActionManager | |
// As public API, optimize for simplicity by only providing a Result and not throwing. | |
func getProfile(id: String, completion: @escaping (Result<Profile>) -> Void) { | |
let action = Action<NSNull, Profile>(urlString: "api.com/profile", method: "GET", body: NSNull()) |