Skip to content

Instantly share code, notes, and snippets.

View yarneo's full-sized avatar
💭
I may be slow to respond.

Yarden Eitan yarneo

💭
I may be slow to respond.
View GitHub Profile
NSDictionary *dogBreeds = @{@”Bugsy” : @”Pug”,
@”Marcelle” : @”Chow Chow”,
@”Daisy” : @”Labrador”;
NSString *name = @"Chloe's breed is: ";
NSString *breed = dogBreeds[@"Chloe"];
/* Crash at runtime because breed is null */
NSString *message = [name stringByAppendingString:breed];
protocol Summable { func +(lhs: Self, rhs: Self) -> Self }
extension Int: Summable {}
extension Double: Summable {}
extension String: Summable {}
func sum<T: Summable>(lhs:T, _ rhs:T) -> T {
return lhs + rhs
}
sum("Hello ", "World") // "Hello World"
func calculateCircle(radius : Double) ->
(area : Double, circumference : Double, diameter : Double) {
return (M_PI * pow(radius, 2), 2 * M_PI * radius, 2 * radius)
}
enum Person {
case FullName(String)
case personID(Int)
init(personID: Int) {
if personID == 123456789 {
self = .FullName(“Barack Obama”)
} else {
self = .personID(personID)
}
}
struct Dog {
var name: String
var type: String
init(name: String, type: String) {
self.name = name
self.type = type
}
}
var aDog = Dog(name: "Bugsy", type: "Pug")
func bouncerResponse(job: String, age: Int, bribe: Int) -> String? {
switch (job, age, bribe) {
case (let j, _, _) where (j.rangeOfString(“model”) != nil) :
return “come in, welcome, the VIP is that way :)”
case (_, 0..<21, _): return “too young bro”
case (“Owner of OMNIA”, 32, _):
return “sorry, we don’t let our competitors in”
/**
An MDCShapeGenerating for creating shaped rectangular CGPaths.
By default MDCRectangleShapeGenerator creates rectangular CGPaths.
Set the corner and edge treatments to shape parts of the generated path.
*/
@interface MDCRectangleShapeGenerator : NSObject <MDCShapeGenerating>
/**
The corner treatments to apply to each corner.
- (MDCPathGenerator *)pathGeneratorForCornerWithAngle:(CGFloat)angle
andCut:(CGFloat)cut {
MDCPathGenerator *path =
[MDCPathGenerator pathGeneratorWithStartPoint:CGPointMake(0, cut)];
[path addLineToPoint:CGPointMake(MDCSin(angle) * cut, MDCCos(angle) * cut)];
return path;
}
- (MDCPathGenerator *)pathGeneratorForCornerWithAngle:(CGFloat)angle
andRadius:(CGFloat)radius {
MDCPathGenerator *path =
[MDCPathGenerator pathGeneratorWithStartPoint:CGPointMake(0, radius)];
[path addArcWithTangentPoint:CGPointZero
toPoint:CGPointMake(MDCSin(angle) * radius, MDCCos(angle) * radius)
radius:radius];
return path;
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (self.layer.shapeGenerator) {
if (CGPathContainsPoint(self.layer.shapeLayer.path, nil, point, true)) {
return self;
} else {
return nil;
}
}
return [super hitTest:point withEvent:event];
}