This file contains hidden or 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
- (void)print { | |
// self.wkWebView はプロジェクト内でのWKWebViewインスタンスに差し替えてください。 | |
// PrintInfo を作る | |
UIPrintInfo *printInfo = [UIPrintInfo printInfo]; | |
printInfo.outputType = UIPrintInfoOutputGeneral; | |
printInfo.jobName = self.wkWebView.title; | |
printInfo.orientation = UIPrintInfoOrientationPortrait; | |
printInfo.duplex = UIPrintInfoDuplexLongEdge; | |
// PrintInteractionController を作る |
This file contains hidden or 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 ProtocolA {} | |
class A<T> {} | |
class B {} | |
class C {} | |
class AB: A<B>{} | |
extension AB: ProtocolA{} | |
assert(AB() is ProtocolA) | |
assert(!(A<C>() is ProtocolA)) |
This file contains hidden or 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 ProtocolA {} | |
class A<T> {} | |
class B {} | |
class C {} | |
extension A: ProtocolA where T: ClassB {} // extension of type 'A' with constraints cannot have an inheritance clause | |
assert(A<B>() is ProtocolA) | |
assert(!(A<C>() is ProtocolA)) |
This file contains hidden or 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 Hoge { | |
let name: String | |
let age: Int | |
init(name: String, age: Int = 0 ) { | |
self.name = name | |
self.age = age | |
} | |
} | |
protocol NameInitializable { |
This file contains hidden or 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
/* 最後の評価を保持しないようになった */ | |
eval( '42; if (true) {}' ); // ES5 => 42 | |
eval( '42; if (true) {}' ); // ES6 => undefined |
This file contains hidden or 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
// Dictionary と nil | |
// nil を代入すると"hoge"キーは消える | |
var dic: [String: Int] = ["hoge": 1, "foo": 2] | |
dic["hoge"] = nil | |
dic // ["foo": 2] | |
// Valueの型を Int? にしても、nil を代入すると"hoge"キーは消える | |
var dic2: [String: Int?] = ["hoge": 1, "foo": 2] | |
dic2["hoge"] = nil |
This file contains hidden or 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
class MyClass { | |
lazy var calculate1: () -> Int = self.calculate | |
lazy var calculate2: () -> Int = { | |
self.calculate() | |
}() | |
} | |
// calculate1 は 型 () -> Int より、calculate2と同じ、クロージャーが代入される。見た目はselfをキャプチャしていないかのように見えてしまうけど、calculate2がselfに循環参照を起こすのと同じように、calculate1も循環参照を生む。 |
This file contains hidden or 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
class File { | |
var content: Content { | |
return Content(path:self.path) | |
} | |
} |
This file contains hidden or 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 PhoneType{ | |
var number:String { get } | |
func callTo(number:String) | |
} | |
extension PhoneType { | |
func callTo(number:String) { | |
print("Call to \(number) from \(self.number)") | |
} |
This file contains hidden or 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
// A とそのサブクラス B が、"プロパティnameを持つ" SomeProtocolに準拠することを宣言。 | |
class A {} | |
class B: A {} | |
protocol SomeProtocol { var name: String { get } } | |
extension A: SomeProtocol {} | |
// Aにnameのデフォルト実装を用意 | |
extension SomeProtocol where Self: A { | |
var name: String { return "My name is A" } | |
} |