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
@interface className() | |
//create a property as dispatch_queue_t | |
@property (nonatomic) dispatch_queue_t concurrentQueue; | |
@end | |
@implementation className | |
//implement a lazy initializer | |
- (dispatch_queue_t)concurrentQueue |
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
protocol cellIndexPathForUITextFieldDelegate:class { | |
var cellIndexPath: NSIndexPath? {get set} | |
} | |
extension UITextField: cellIndexPathForUITextFieldDelegate { | |
private struct AssociatedKeys { | |
static var kNSIndexPath = "kNSIndexPath" | |
} | |
var cellIndexPath: NSIndexPath? { |
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
enum CommunicatorError: CustomStringConvertible, ErrorType { | |
/** | |
used to communicate unknown error to user. This is a rear case. | |
*/ | |
case CommunicatorUnknownError | |
/** | |
used to communicate network errors | |
*/ | |
case CommunicatorNetworkError | |
/** |
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
<key>NSAppTransportSecurity</key> | |
<dict> | |
<key>NSAllowsArbitraryLoads</key> | |
<true/> | |
</dict> |
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 makeRequest(success:(response:AnyObject)->(), failure:(error:CommunicatorError)->()) { | |
/** | |
Play with resp api take inspiration | |
https://grokswift.com/simple-rest-with-swift/ | |
*/ | |
let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration() | |
let session = NSURLSession(configuration: sessionConfig, delegate: nil, delegateQueue: nil) | |
let URL = NSURL(string: "http://jsonplaceholder.typicode.com/posts") | |
//let URL = NSURL(string: "http://private-anon-827bc57e0-andresbrun.apiary-mock.com/api/v3/search_suggestions") | |
let request = NSMutableURLRequest(URL: URL!) |
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
lazy var concurrentQueue:dispatch_queue_t = { | |
var __dispatchToken:dispatch_once_t = 0 | |
var queue:dispatch_queue_t? | |
let qos = qos_class_t(QOS_CLASS_USER_INITIATED.rawValue) | |
let attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT, qos, 2); | |
dispatch_once(&__dispatchToken, { | |
queue = dispatch_queue_create("com.companyname.concurrent", attr); | |
}); | |
return queue! | |
}() |
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
lazy var dateFormatter:NSDateFormatter = { | |
var dateFormatter:NSDateFormatter? | |
var __dispatchToken: dispatch_once_t = 0 | |
dispatch_once(&__dispatchToken) { | |
dateFormatter = NSDateFormatter() | |
/** | |
setting the default locale to Germany // for USA use us_US | |
*/ | |
dateFormatter?.locale = NSLocale(localeIdentifier: "de_DE") | |
/** |
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
<key>NSAppTransportSecurity</key> | |
<dict> | |
<key>NSExceptionDomains</key> | |
<dict> | |
<key>yourserver.com</key> | |
<dict> | |
<!--Include to allow subdomains--> | |
<key>NSIncludesSubdomains</key> | |
<true/> | |
<!--Include to allow HTTP requests--> |
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
/** | |
Telling the system to dispatch after 2 seconds on the main queue | |
*/ | |
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2.00 * Double(NSEC_PER_SEC))) | |
dispatch_after(dispatchTime, dispatch_get_main_queue()) { [weak self] in | |
guard let strongSelf = self, let aProperty = aProperty else { | |
return | |
} | |
// Do something with aProperty |
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
// | |
// Extensions.swift | |
// PaylevenSDKSwiftExample | |
// | |
// Created by Bob Obi on 7/2/15. | |
// Copyright (c) 2015 Obi Bob Godwin. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
OlderNewer