Skip to content

Instantly share code, notes, and snippets.

[[[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);
}];
guard let path = Bundle.main.path(forResource: "MLK", ofType: "mp3") else {
return
}
let url = URL(fileURLWithPath: path)
player = AVAudioPlayerNode()
audioEngine.attach(player)
do {
- (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;
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
}
}
import UIKit
import Foundation
enum Direction {
case Clockwise
case Counterclockwise
}
class ViewController: UIViewController {
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))
})
}
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
}
}
extension String {
subscript (i: Int) -> Character {
return self[self.startIndex.advanceBy(i)]
}
}
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
}
class func matchesForRegexInText(regex: String!, text: String!, captureGroupIndices:[Int]) -> [[String]] {
do {
let regex = try NSRegularExpression(pattern: regex, options: [.CaseInsensitive])
let nsString = text as NSString
let results = regex.matchesInString(text, options: [], range: NSMakeRange(0, nsString.length))
return results.map { (textCheckingResult:NSTextCheckingResult) -> [String] in
var returnValue = [String]()
returnValue.append(nsString.substringWithRange(textCheckingResult.range))
if textCheckingResult.numberOfRanges != captureGroupIndices.count + 1 {