This file contains 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
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]; |
This file contains 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
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" |
This file contains 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 calculateCircle(radius : Double) -> | |
(area : Double, circumference : Double, diameter : Double) { | |
return (M_PI * pow(radius, 2), 2 * M_PI * radius, 2 * radius) | |
} |
This file contains 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
enum Person { | |
case FullName(String) | |
case personID(Int) | |
init(personID: Int) { | |
if personID == 123456789 { | |
self = .FullName(“Barack Obama”) | |
} else { | |
self = .personID(personID) | |
} | |
} |
This file contains 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
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") |
This file contains 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 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” |
This file contains 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
/** | |
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. |
This file contains 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
- (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; | |
} |
This file contains 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
- (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; | |
} |
This file contains 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 *)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]; | |
} |
OlderNewer