Skip to content

Instantly share code, notes, and snippets.

var origin: CGPoint?
var radius: CGFloat?
var locations: [CGFloat]?
var colors: [UIColor]?
override func drawInContext(ctx: CGContext!) {
super.drawInContext(ctx)
if let colors = self.colors {
if let locations = self.locations {
if let origin = self.origin {
@MrBendel
MrBendel / gist:ceebf4611e75c613642a
Created June 23, 2015 20:22
Swift for JS Developers
func SetTimeout(delay: Int64, callback: () -> Void) {
var delta: Int64 = delay * Int64(NSEC_PER_SEC)
var time = dispatch_time(DISPATCH_TIME_NOW, delta)
dispatch_after(time, dispatch_get_main_queue(), callback);
}
- (void)startProcessing
{
// Setup CADisplayLink which will callback displayPixelBuffer: at every vsync.
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkCallback:)];
[[self displayLink] addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[self displayLink] setPaused:YES];
// Setup AVPlayerItemVideoOutput with the required pixelbuffer attributes.
NSDictionary *pixBuffAttributes = @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange)};
self.playerItemOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes];
// the cell creation logic
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UVLVideoCell *videoCell = (UVLVideoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UVLVideoCell class]) forIndexPath:indexPath];
NSInteger index = 1 + indexPath.item%2;
NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"flak_0%i", index] withExtension:@"mp4" subdirectory:@"videos"];
[videoCell loadVideoURL:sampleURL];
return videoCell;
#import "UIAlertViewWithCallback.h"
static NSMutableDictionary *__UIAlertViewCachedViews;
@interface UIAlertViewWithCallback ()<UIAlertViewDelegate>
@property (nonatomic, strong) UIAlertView *alertView;
@property (nonatomic, copy) UIAlertViewConfirmationCallback callback;
@end
- (void)generateRectsForCharactersInLinks
{
if (self.links.count == 0)
return;
CGRect textRect = [self textRectForBounds:self.bounds limitedToNumberOfLines:self.numberOfLines];
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, textRect);
CTFrameRef frame = CTFramesetterCreateFrame(self.framesetter, CFRangeMake(0, (CFIndex)[self.attributedText length]), path, NULL);
- (CGSize)sizeThatFits:(CGSize)size{
if (!self.attributedText)
{
return [super sizeThatFits:size];
}
NSUInteger length = 0;
if ([self.text respondsToSelector:@selector(length)])
{
length = [self.text length];
int64_t durationValue = [[coder decodeObjectForKey:@"durationTimeValue"] intValue];
int32_t durationScale = [[coder decodeObjectForKey:@"durationTimeScale"] intValue];
int64_t startValue = [[coder decodeObjectForKey:@"startTimeValue"] intValue];
int32_t startScale = [[coder decodeObjectForKey:@"startTimeScale"] intValue];
CMTime duration;
duration.value = durationValue;
duration.timescale = durationScale;