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
| extension String { | |
| func matches(pattern: String, options: NSRegularExpressionOptions = []) -> Bool { | |
| do { | |
| let regex = try NSRegularExpression(pattern: pattern, options: options) | |
| return (regex.firstMatchInString(self, options: [], range: NSRange(location: 0, length: self.characters.count)) != nil) | |
| } catch { | |
| return false | |
| } | |
| } | |
| } |
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
| extension UIView { | |
| func shake() { | |
| let anim = CAKeyframeAnimation( keyPath:"transform" ) | |
| anim.values = [ | |
| NSValue( CATransform3D: CATransform3DMakeTranslation(-5, 0, 0 ) ), | |
| NSValue( CATransform3D: CATransform3DMakeTranslation( 5, 0, 0 ) ) | |
| ] | |
| anim.autoreverses = true | |
| anim.repeatCount = 2 | |
| anim.duration = 7/100 |
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
| if(!self.superview){ | |
| NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication] windows] reverseObjectEnumerator]; | |
| for (UIWindow *window in frontToBackWindows) { | |
| if (window.windowLevel == UIWindowLevelNormal) { | |
| [window addSubview:self]; | |
| break; | |
| } | |
| } |
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
| var canvas = document.createElement("canvas"); | |
| var ctx = canvas.getContext("2d"); | |
| canvas.width = 512; | |
| canvas.height = 480; | |
| document.body.appendChild(canvas); | |
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 testFetchRequestWithMockedManagedObjectContext() { | |
| class MockNSManagedObjectContext: NSManagedObjectContext { | |
| override func executeFetchRequest(request: NSFetchRequest!, error: AutoreleasingUnsafePointer<NSError?>) -> [AnyObject]! { | |
| return [["name": "Johnny Appleseed", "email": "[email protected]"]] | |
| } | |
| } | |
| let mockContext = MockNSManagedObjectContext() | |
| let fetchRequest = NSFetchRequest(entityName: "User") | |
| fetchRequest.predicate = NSPredicate(format: "email ENDSWITH[cd] %@", "@apple.com") |
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 testAsynchronousURLConnection() { | |
| let URL = NSURL(string: "http://nshipster.com/")! | |
| let expectation = expectationWithDescription("GET \(URL)") | |
| let session = NSURLSession.sharedSession() | |
| let task = session.dataTaskWithURL(URL) { data, response, error in | |
| XCTAssertNotNil(data, "data should not be nil") | |
| XCTAssertNil(error, "error should be nil") | |
| if let HTTPResponse = response as? NSHTTPURLResponse, |
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
| // | |
| // SSImageVC.swift | |
| // SSImageVC | |
| // | |
| // Created by Carrl on 16/3/7. | |
| // Copyright © 2016年 monk-studio. All rights reserved. | |
| // | |
| import UIKit |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title></title> | |
| </head> | |
| <body> | |
| <img src="xx.jpg" alt="My Avatar" id="avatar" title="aaa"/> | |
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
| UIGraphicsBeginImageContextWithOptions(CGSize(), false, UIScreen.mainScreen().scale) | |
| //// Text Drawing | |
| let textRect = CGRectMake(0, 0, 0, 14) | |
| let textTextContent = NSString(string: skillLocal) | |
| let textStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy() as! NSMutableParagraphStyle | |
| textStyle.alignment = .Center | |
| let rectanglePath = UIBezierPath(roundedRect: CGRectMake(), cornerRadius:) | |
| fillColor.setFill() | |
| rectanglePath.fill() |