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 json (url: String, response: (AnyObject, NSError?) -> Void) { | |
NSURLConnection.sendAsynchronousRequest(NSURLRequest(URL: NSURL(string: url)), queue: NSOperationQueue.currentQueue(), completionHandler:{response, data, error in | |
var jsonError : NSError? | |
var json : AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: &jsonError) | |
response (json, jsonError) | |
}) | |
} | |
/* usage | |
json("http://www.someurl.com/some/json", {jsonObj, error in |
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
//#include "unistd.h" | |
//#include "netdb.h" | |
- (BOOL)isNetworkAvailable { | |
char *hostname; | |
struct hostent *hostinfo; | |
hostname = "google.com"; | |
hostinfo = gethostbyname (hostname); | |
if (hostinfo == NULL){ | |
NSLog(@"-> no connection!\n"); |
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
- (CCSprite*)spriteWithSize:(CGSize)size andColor:(ccColor4B)color | |
{ | |
CCSprite *sprite = [CCSprite node]; | |
GLubyte *buffer = malloc(sizeof(GLubyte)*4); | |
for (int i=0;i<4;i++) {buffer[i]=255;} | |
CCTexture *tex = [[CCTexture alloc] initWithData:buffer pixelFormat:CCTexturePixelFormat_RGBA4444 pixelsWide:1 pixelsHigh:1 contentSizeInPixels:size contentScale:1]; | |
[sprite setTexture:tex]; | |
[sprite setTextureRect:CGRectMake(0, 0, size.width, size.height)]; | |
free(buffer); | |
[sprite setColor:[CCColor colorWithCcColor4b:color]]; |
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 ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
var dataSource: [String] = [] | |
var table: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
for _ in 0...10 { |
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 String { | |
subscript (i: Int) -> String { | |
return String(Array(self)[i]) | |
} | |
} |
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 UILabel { | |
func addAttributedString (text: String, color: UIColor, font: UIFont) { | |
var string = self.text == nil ? "" : self.text! | |
let newString = string + text | |
let range = NSRange(location: countElements(string), length: countElements(text)) | |
var att: NSMutableAttributedString? | |
if let a = self.attributedText { | |
att = NSMutableAttributedString (attributedString: a) |
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 filtered = filter (dataSource) { $0.rangeOfString(searchText) != nil } |
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
[](https://travis-ci.org/facebook/AsyncDisplayKit) | |
[](http://cocoapods.org/?q=AsyncDisplayKit) | |
[]() |
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
@IBOutlet var mapView: MKMapView! | |
func setupMapBlur () { | |
var blur: UIView! | |
if ios8() { | |
blur = UIVisualEffectView (effect: UIBlurEffect (style: UIBlurEffectStyle.Light)) | |
} else { | |
blur = FXBlurView (frame: view.frame) | |
} | |
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
override class func drawRect( | |
bounds: CGRect, | |
withParameters parameters: NSObjectProtocol!, | |
isCancelled isCancelledBlock: asdisplaynode_iscancelled_block_t!, | |
isRasterizing: Bool) { | |
let context = UIGraphicsGetCurrentContext() | |
CGContextSaveGState(context) | |
CGContextSetShadowWithColor(context, CGSize (width: 0, height: 1), 10, UIColor.TitleColor().CGColor) |
OlderNewer