Swift <-> Kotlin

Cf72ecd4105b5818fcabcc0c0aaeee22?s=47 jsugai
November 24, 2017
150

Swift <-> Kotlin

Cf72ecd4105b5818fcabcc0c0aaeee22?s=128

jsugai

November 24, 2017
Tweet

Transcript

  1. 7.

    ஌Γ͍ͨ Ͳ͏΍ͬͨΒ։ൃܥͷ৘ใΛݟ͚ͭΒΕΔͷ͔? •ॳֶ͔Βগ͠੒௕ͯ͘͠Δͱײ͡ΔṖͷয૩ײ
 StoryBoard ͷ༗ແ΍؅ཧํ๏, Segue ΍ View पΓͳͲ
 ઃܭͷࠜװʹؔΘΓͦ͏ͳͱ͜Ζ͸ɺௐ΂ͯ΋݁ہओྲྀ͕෼͔Βͳ͍

    •໨ʹͭ͘໰୊ͷଟ͘શ෦͸ Swift Ͱ͸ͳ͘ iOS ͕ݪҼ
 Swift ͷ໰୊͸ίϯύΠϧ͙࣌ؒΒ͍ʁʢίϯύΠϥͷख़੒౓ʣ
 iOS ͷ໰୊͸ۀΛഎෛ͏͔͠ͳ͍ʁ
  2. 15.
  3. 16.

    ධՁઓུ:άϩʔόϧม਺ v_localOne = F_globalVar(); https://railsware.com/blog/2014/06/11/global-variables-in-swift-are-not-variables/ @HMPCBMJOJU@GVOD SwiftͰͷάϩʔόϧม਺͸λΠϓίϯςΩετͷ֎ଆʹ഑ஔ͞ΕΔɻʢͱυΩϡϝϯτʹॻ͍ͯ͋Δʣ
 C lang తʹߟ͑ΔͳΒ

    longjmp ͢ΔͱϨδελΛॻ͖׵͑ͨ৔߹ʹϩʔΧϧม਺είʔϓ͸஋ͷר͖໭͕͠
 อূ͞ΕΔ(auto) ͕άϩʔόϧม਺͸ר͖໭͞Εͳ͍ʹະఆٛͷ஋ͱͳΔ࣮૷͕ଟ͍ɻ
 Thread Context Λ Switch ͢Δͨͼʹ Global ม਺ͷר͖໭͠Λߦ͏ʹ͸ɺ෭࡞༻Λ൐͏͜ͱ͕ଟ͘SwiftͰ͸άϩʔόϧ ม਺ͷॳظԽΛؔ਺ݺͼग़͠ʹஔ͖׵͑Δ͜ͱͰ setjmp/longjmp Ͱͷ࣮ߦίʔυΛύλʔϯԽͯ͠࠷దԽޮ཰ΛߴΊͯ ͍Δʁ https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html#//apple_ref/doc/uid/TP40014097-CH14-XID_382 ಡ·ͳͯ͘0,
  4. 18.

    ධՁઓུ: •ΞΫηα͸ࣝผࢠ(Identifire)ʹରͯ͠෇༩͞ΕΔ •ࣝผࢠ(Identifire)ͱ͸ࢀরΛ൑அ͢ΔͨΊͷ໊લ • didset/willset ͸ mutating ͳͲͱಉ͡λΠϛϯάͰίϯύΠϥ ͕ϝιουΛੜ੒͢Δʢ಺෦తʹϝιουΛੜ੒͢Δʣ •

    ม਺ͷΞΫηαϒϩοΫ 
 OBNFTQBDF\ TUSVDU"DDFTTPST\ 4UPSBHF,JOE,JOE 'VOD%FDM (FUOVMMQUS  4FUOVMMQUS  .BUFSJBMJ[F'PS4FUOVMMQUS 'VOD%FDM "EESFTTOVMMQUS  .VUBCMF"EESFTTOVMMQUS 'VOD%FDM 8JMM4FUOVMMQUS  %JE4FUOVMMQUS ^ ^FOEBOPOZNPVTOBNFTQBDF
  5. 20.
  6. 24.

    ށ࿭͏͜ͱ Property Λॻ͖׵͑Δલ/ޙͰݺ͹ΕΔ؂ࢹػೳ ...
 var age: Int = 0 {

    willSet { // <- age ʹ஋Λ୅ೖ͢Δ࣌ʹݺ͹ΕΔ println("age willSet:\(age) -> \(newValue)") } didSet { // <- age ʹ஋͕୅ೖ͞Εͨޙʹݺ͹ΕΔ println("age didSet :\(oldValue) -> \(age)") } }
 ... ศར͕ͩ Kotlin Ͱ͸... custom setter/getter ͋ͨΓ͕མͱ͠ॴ? 
 ͨͩ Kotlin Ͱؤுͬͯදݱ͔ͨ͠Βͱݴͬͯར༻཰͕ߴ͍ͱ΋ࢥ͑ͳ͍ɻ
 ͜͏͍͏ͷ͸ݴޠ࢓༷Ͱදݱ͞ΕΔͱ࠷ߴͳػೳͷ୅දɻ ͨͩɺਖ਼௚͍ͬͯϕετϓϥΫςΟε͕෼͔Βͳͯ͘ɺ࢖ͬͯͳ͍/࢖͑ͯͳ͍....
 ϕετϓϥΫςΟε୭͔ڭ͑ͯɻҒ͍ਓɻΤϩ͍ਓʂ
  7. 26.

    
 func hoge() { guard let name = nameField.text else

    {
 return
 }
 guard let addr = addrField.text else {
 return
 }
 sendLog(LOG_TYPE_FIELD, name, addr)
 ... }

  8. 27.
  9. 28.

    
 func hoge() { val name = nameField?.text ?:return val

    addr = addrField?.text ?:return sendLog(LOG_TYPE_FIELD, name, addr)
 ... }

  10. 30.

    
 func hoge() { guard let name = nameField.text else

    {
 showMessage("please input name field") // local scope Λͭ͘ΕΔ͔Β return ͷલʹ΋ॲཧok!
 return
 }
 ... }
 
 func hoge() { if( nameField?.text == null ) { // ݹయతͳํ๏
 showMessage("please input name field") 
 return
 }
 ... }

  11. 32.

    private inline fun <T> T?.checkNull(ifNull: ()-> T ): T =

    this ?: ifNull()
 
 func hoge() { nameField?.text.checkNull { showMessage("please input name field") return }
 ... }

  12. 33.