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
//: Playground - noun: a place where people can play | |
import Cocoa | |
var str = "Hello, playground" | |
@objc protocol Thing { | |
func doThing(x: String) throws -> String | |
} |
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
// Solution: if I use "class" instead of "AnyObject", then it’s a pure Swift solution: | |
// http://inessential.com/2015/07/23/swift_diary_3_arrays_protocols_and_p | |
// https://twitter.com/_mattrubin/status/624266521896992768 | |
// Or… AnyObject may be marked @objc, but it is in fact a native Swift feature: | |
// https://twitter.com/jckarter/status/624270700614942721 |
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
import Cocoa | |
protocol Thing { | |
var x: String {get} | |
init(s: String) | |
} | |
class Foo: Thing { | |
let x: String |
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
// How do you do this in Swift? | |
- (Class)classToUse { | |
return [Foo class]; // assume it's something else sometimes | |
} | |
- (id)generateThingForString:(NSString *)s { | |
Class thingClass = [self classToUse]; | |
return [[thingClass alloc] initWithString:s]; | |
} |
NewerOlder