##iOS Testing Reference Links
This file contains hidden or 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
| { | |
| "valid_promotion": { | |
| "created_at" : "2016-01-11T19:14:21.123-02:00", | |
| "discount_percentage" : 15, | |
| id : 16719297, | |
| "product_current_price_cents" : 12300, | |
| "product_id" : 14454151, | |
| "product_original_price_cents" : 12300, | |
| "product_promotional_price_cents" : 10400, | |
| "promotion_expire_at" : "2016-01-14T23:59:59.999-02:00", |
This file contains hidden or 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 pngImageData = UIImagePNGRepresentation(image) | |
| let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] | |
| let imagePath = documentsURL.URLByAppendingPathComponent("remela.png") | |
| pngImageData!.writeToFile(imagePath.path!, atomically: true) |
This file contains hidden or 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
| // 1. SynchonousRequest | |
| let urlPath: String = "YOUR_URL_HERE" | |
| var url: NSURL = NSURL(string: urlPath)! | |
| var request1: NSURLRequest = NSURLRequest(URL: url) | |
| var response: AutoreleasingUnsafeMutablePointer<NSURLResponse? >= nil | |
| var error: NSErrorPointer = nil | |
| var dataVal: NSData = NSURLConnection.sendSynchronousRequest(request1, returningResponse: response, error:nil)! | |
| var err: NSError |
This file contains hidden or 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
| // This little program takes ~ 6 seconds to compile on my MacBook Pro Late 2013. | |
| // It compiles and works as expected. But the type checker spends a lot of time | |
| // on the function at the end. | |
| // In my actual project, I have much more code like this, and it results in very | |
| // long compile times. So I'd like to know if there is something I can do to | |
| // speed that up. | |
| protocol DefaultInitializable { init() } | |
| extension Float : DefaultInitializable {} |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # checks if branch has something pending | |
| function parse_git_dirty() { | |
| git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*" | |
| } | |
| # gets the current git branch | |
| function parse_git_branch() { | |
| git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" |
This file contains hidden or 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 parseJSON(jsonString: String) -> AnyObject { | |
| // ensure that some data arrived | |
| guard let validData = jsonString.dataUsingEncoding(NSUTF8StringEncoding) where validData.length > 0 else { | |
| print("**** NO DATA to be parse!") | |
| return NSNull() | |
| } | |
This file contains hidden or 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
| [ | |
| { | |
| "id": 1, | |
| "user_avatar": "http://placehold.it/128/4597CE/F7E42D/&text=FS", | |
| "user_fullname": "Frank Simpson" | |
| }, | |
| { | |
| "id": 2, | |
| "user_avatar": "http://placehold.it/128/4597CE/F3F4F5/&text=HH", |
This file contains hidden or 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(e,n,t){function r(e,n){return typeof e===n}function o(){var e,n,t,o,i,s,a;for(var f in C)if(C.hasOwnProperty(f)){if(e=[],n=C[f],n.name&&(e.push(n.name.toLowerCase()),n.options&&n.options.aliases&&n.options.aliases.length))for(t=0;t<n.options.aliases.length;t++)e.push(n.options.aliases[t].toLowerCase());for(o=r(n.fn,"function")?n.fn():n.fn,i=0;i<e.length;i++)s=e[i],a=s.split("."),1===a.length?Modernizr[a[0]]=o:(!Modernizr[a[0]]||Modernizr[a[0]]instanceof Boolean||(Modernizr[a[0]]=new Boolean(Modernizr[a[0]])),Modernizr[a[0]][a[1]]=o),g.push((o?"":"no-")+a.join("-"))}}function i(e){var n=w.className,t=Modernizr._config.classPrefix||"";if(x&&(n=n.baseVal),Modernizr._config.enableJSClass){var r=new RegExp("(^|\\s)"+t+"no-js(\\s|$)");n=n.replace(r,"$1"+t+"js$2")}Modernizr._config.enableClasses&&(n+=" "+t+e.join(" "+t),x?w.className.baseVal=n:w.className=n)}function s(e){return e.replace(/([a-z])-([a-z])/g,function(e,n,t){return n+t.toUpperCase()}).replace(/^-/,"")}function a(e,n){return!!~(""+e).indexOf( |
This file contains hidden or 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 | |
| /// Return a thread-local object, creating it if it has not already been created | |
| /// | |
| /// :param: create closure that will be invoked to create the object | |
| /// :returns: object of type T | |
| public func cachedThreadLocalObjectWithKey<T: AnyObject>(key: String, create: () -> T) -> T { | |
| if let threadDictionary = NSThread.currentThread().threadDictionary { | |
| if let cachedObject = threadDictionary[key] as T? { | |
| return cachedObject |