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
| // before the change | |
| BAPromise *promise = [self methodThatReturnsAPromise]; | |
| [promise then:^id(id obj) { | |
| NSLog(@"1st"); | |
| return [[self otherMethodThatReturnsAPromise] then:^id(id obj) { | |
| NSLog(@"2nd"); | |
| return obj; | |
| }]; | |
| }]; |
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
| [[[AMPSession currentSession] getRefreshToken] done:^(AMPTokenResponse *obj) { | |
| NSString *token = obj.token; | |
| NSURL *modifieldURL = [Configuration sharedConfiguration].AMPEnvironment == IHRConfigurationPlatformAMPEnvironmentProd ? url : [NSURL URLWithString:@"https://sandbox.iheart.com"]; | |
| NSURLComponents *components = [NSURLComponents componentsWithURL:modifieldURL resolvingAgainstBaseURL:false]; | |
| NSURLQueryItem *regSync = [NSURLQueryItem queryItemWithName:@"regSyncToken" value:token]; | |
| components.queryItems = @[regSync]; | |
| completionHandler(components.URL); | |
| } rejected:^(NSError *error) { | |
| completionHandler(url); | |
| }]; |
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
| guard let path = Bundle.main.path(forResource: "MLK", ofType: "mp3") else { | |
| return | |
| } | |
| let url = URL(fileURLWithPath: path) | |
| player = AVAudioPlayerNode() | |
| audioEngine.attach(player) | |
| do { |
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
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GuideCell" forIndexPath:indexPath]; | |
| if (cell == nil) { | |
| cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"GuideCell"]; | |
| } | |
| Guide *guide = [self.guides objectAtIndex:indexPath.row]; | |
| cell.textLabel.text = guide.name; | |
| cell.detailTextLabel.text = @"xxx"; | |
| return cell; |
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 | |
| extension String { | |
| func containsOnlyWhitespace() -> Bool { | |
| let pattern = "^[\\s]+$" | |
| let regex = try! NSRegularExpression(pattern: pattern, options: .DotMatchesLineSeparators) | |
| let matches = regex.matchesInString(self, options: .ReportCompletion, range: NSMakeRange(0, self.characters.count)) | |
| return matches.count > 0 | |
| } | |
| } |
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 UIKit | |
| import Foundation | |
| enum Direction { | |
| case Clockwise | |
| case Counterclockwise | |
| } | |
| class ViewController: UIViewController { | |
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
| UIView.animateWithDuration(1, animations: { | |
| self.littleView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, CGFloat(M_PI)) | |
| }) { (completed) in | |
| UIView.animateWithDuration(1, animations: { | |
| self.littleView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, CGFloat(M_PI)) | |
| }) | |
| } |
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 numericValue() -> Any? { | |
| if let doubleValue = Double(self) where self.localizedStandardContainsString(".") { | |
| return doubleValue | |
| } else if let intValue = Int(self) { | |
| return intValue | |
| } else { | |
| return nil | |
| } | |
| } |
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 { | |
| subscript (i: Int) -> Character { | |
| return self[self.startIndex.advanceBy(i)] | |
| } | |
| } |
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 memoize<T: Hashable, U>(body: (T -> U, T) -> U) -> (T -> U) { | |
| var cache = [T : U]() | |
| func result(x: T) -> U { | |
| if let q = cache[x] { return q } | |
| let r = body(result, x) | |
| cache[x] = r | |
| return r | |
| } |