Slide 1

Slide 1 text

ΞϧΰϦζϜΛ௨ͯ͡ ΑΓΑ͍ΞϓϦΛ iOSDC 2018 ϨΠɾϑΟοΫε @rayfix

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

ΞϧΰϦζϜ͸ ۀքͷֵ໋Λىͤ͜·͢! ϑΝΠϧ 0 15 30 45 60 ΦʔσΟΦσʔλ ѹॖ͞ΕͨΦʔσΟΦσʔλ

Slide 4

Slide 4 text

ؾ͖ͮ·͔ͨ͠ʁ

Slide 5

Slide 5 text

ALGORITHMS

Slide 6

Slide 6 text

iOS 12 ϚʔέοτΠϯ • ΑΓ଎͘ɺΑΓ൓Ԡྑ͘ • Ξχϝʔγϣϯ͕ҰஈͱεϜʔζʹ • ΞϓϦέʔγϣϯͷىಈ͕࠷େ40%଎͘ • ΩʔϘʔυͷද͕ࣔ࠷େ50%଎͘ • εϫΠϓʹΑΔΧϝϥͷىಈ͕࠷େ70%଎͘ • ෛՙ࣌ͷڞ༗γʔτͷද͕ࣔ࠷େ2ഒ଎͘ iPhone 5s

Slide 7

Slide 7 text

O(1) ఆ਺࣌ؒ O(log n) ର਺ O(n) ઢܗؔ਺ O(n log n) ઢܗର਺ O(n2) ೋ৐࣌ؒ O(nc) ଟ߲ࣜ࣌ؒ O(2n) ؒࢦ਺࣌ؒ O(n!) ֊৐ؔ਺ ϥϯμ΢ͷه߸ εέʔϧ͢Δ εέʔϧ͠ͳ͍

Slide 8

Slide 8 text

O(1) O(log n) O(n) O(n log n) O(n2) O(nc) O(2n) O(n!) Auto Layout Session 202 iOS 12

Slide 9

Slide 9 text

Auto Layout ϨΞ΢τ੍໿ͷ਺ ॲཧ࣌ؒ O(n) iOS 12

Slide 10

Slide 10 text

Layout “Churn” class MyView: UIView { override func updateConstraints() { } } ϨΠΞ΢τ੍໿࠶ॳظԽʹ஫ҙ ̍ඵʹ̍̎̌ճݺͼग़͞ΕΔՄೳੑ͕͋Δ Session 220

Slide 11

Slide 11 text

ίϨΫγϣϯΛޮՌతʹ ࢖༻͢Δํ๏ • ஗Ԇॲཧ΍εϥΠεͷίετΛཧղ͠ͳ͕Βɺ
 ίϨΫγϣϯ࢖͍·͠ΐ͏ • Swiftܕ ͱ FoundationܕͷؒʹϒϦοδ͕ඞཁͰ͢ɻ
 ίετ͸O(1) ͔ΒO(n) Ͱ͢ɻ let story = “σοΧ͍ string" let text = NSMutableAttributedString(string: story) let string = text.string Session 229

Slide 12

Slide 12 text

ԕ͗ͨ͢ڮ let story = “σοΧ͍ string" let text = NSMutableAttributedString(string: story) let string = text.string as NSString for index in 1 ... { } let nsRange = string.range(of: “kitten") n InstrumentsͰܭΓ·͠ΐ͏

Slide 13

Slide 13 text

ΞϧΰϦζϜΛड͚ೖΕΔ Crusty Dave Abrahams @DaveAbrahams Swift library designer / Professor of blowing-your-mind @apple @Mind your own business . Session 223

Slide 14

Slide 14 text

γΣʔϓͷ࡟আ extension Canvas { mutating func deleteSelection() { for i in 0 ..< shapes.count { if shapes[i].isSelected { shapes.remove(at: i) } } } }

Slide 15

Slide 15 text

γΣʔϓͷ࡟আ extension Canvas { mutating func deleteSelection() { for i in 0 ..< shapes.count { if shapes[i].isSelected { shapes.remove(at: i) } } } } TRAP

Slide 16

Slide 16 text

γΣʔϓͷ࡟আ (V2) extension Canvas { mutating func deleteSelection() { var i = 0 while i < shapes.count { if shapes[i].isSelected { shapes.remove(at: i) } i += 1 } } }

Slide 17

Slide 17 text

γΣʔϓͷ࡟আ (V2) extension Canvas { mutating func deleteSelection() { var i = 0 while i < shapes.count { if shapes[i].isSelected { shapes.remove(at: i) } i += 1 } } } ͋Εʁ

Slide 18

Slide 18 text

γΣʔϓͷ࡟আ (V3) extension Canvas { mutating func deleteSelection() { var i = 0 while i < shapes.count { if shapes[i].isSelected { shapes.remove(at: i) } else { i += 1 } } } }

Slide 19

Slide 19 text

γΣʔϓͷ࡟আ (V4) extension Canvas { mutating func deleteSelection() { for i in (0..

Slide 20

Slide 20 text

γΣʔϓͷ࡟আ (V4) extension Canvas { mutating func deleteSelection() { for i in (0..

Slide 21

Slide 21 text

Ϗοάɾσʔλ

Slide 22

Slide 22 text

γΣʔϓͷ࡟আ (V5) extension Canvas { mutating func deleteSelection() { shapes.removeAll { $0.isSelected } } } O(n)

Slide 23

Slide 23 text

ΩʔϙΠϯτ •ඪ४ϥΠϒϥϦͷΞϧΰϦζϜΛ
 ࢖ͬͨ΄͏͕෼͔Γ΍͍͢ •ඪ४ϥΠϒϥϦͷΞϧΰϦζϜ͸ੑೳͷ
 ༧ଌੑ͕͋Δ •O(1) Ҏ֎͸ඞͣυΩϡϝϯτ͞Ε͍ͯΔ

Slide 24

Slide 24 text

Raw LoopΛ࢖Θͳ͍ http://sean-parent.stlab.cc/presentations/ 2013-09-11-cpp-seasoning/cpp-seasoning.pdf Sean Parent @SeanParent Software Engineer at Adobe C++ Seasoning

Slide 25

Slide 25 text

Raw LoopΛ࢖Θͳ͍ •ඪ४ͷΞϧΰϦζϜΛ࢖͏ •ඪ४ͷΞϧΰϦζϜΛ࣮૷͢Δ •શͯͷίʔυ͸ϥΠϒϥϦʔԽ͢Δ •৽͍͠ΞϧΰϦζϜΛ։ൃ͢Δ •༗໊ʹͳΔ


Slide 26

Slide 26 text

׽ࣈ͕೉͍͠ cards.shuffle() let shuffledIndices = cards.indices.shuffled() ฤूεςοϓ for (new, orig) in shuffledIndices.enumerated() { newCards[new] = originalCards[orig] } collectionView.performBatchUpdates({ for ( ) in shuffledIndices.enumerated() { let src = IndexPath(item: orig, section: 0) let dst = IndexPath(item: new, section: 0) collectionView.moveItem(at: src, to: dst) } }, completion: nil) new orig, Session 225 όά ʢnew, orig) ͕ਖ਼͍͠

Slide 27

Slide 27 text

ࠓ೔ͷӳޠڭࣨ

Slide 28

Slide 28 text

ΤϏϯάϋ΢ε๨٫ۂઢ R = e− t S

Slide 29

Slide 29 text

zip 2 ( ) , 0 ( ) , 1 ( ) , 4 ( ) , 3 ( ) ,

Slide 30

Slide 30 text

sort 2 ( ) , 0 ( ) , 1 ( ) , 4 ( ) , 3 ( ) ,

Slide 31

Slide 31 text

δΣωϦοΫʹ extension Collection { func sortedWithIndices(by order: (Element, Element) -> Bool) -> ([Element], moves: [(from: Index, to: Index)]) { let elementsAndIndices = zip(self, self.indices) let sorting = elementsAndIndices.sorted { order($0.0, $1.0) } let elements = sorting.map { $0.0 } let moves = sorting.enumerated().map { (offset, element) -> (from: Index, to: Index) in var toIndex: Index = startIndex formIndex(&toIndex, offsetBy: offset) let fromIndex: Index = element.1 return (from: fromIndex, to: toIndex) }.filter { $0.from != $0.to } return (elements, moves: moves) } }

Slide 32

Slide 32 text

ࠩ෼ϥΠϒϥϦʔ • DeepDiff • Differ • DifferenceKit • IGListKit • RxDataSources DifferenceKit Heckel’s Algorithm O(n)

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Summary •ΞϧΰϦζϜΛษڧ͠·͠ΐ͏ •ඪ४ϥΠϒϥϦʔΛಡΈ·͠ΐ͏ •Raw Loop Λආ͚·͠ΐ͏

Slide 35

Slide 35 text

͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠!