Upgrade to Pro — share decks privately, control downloads, hide ads and more …

(Appleが)やりたい放題 Swift Attributes

(Appleが)やりたい放題 Swift Attributes

札幌iPhoneアプリ開発者勉強協会資料
https://devsap.connpass.com/event/207402/

題目
1) SwiftUIで説明しづらい@定義
2) Swift Attributesを大枠で分けてみる
3) Swift Attributesから見るSwiftの進化
4) まとめ

notoroid

March 24, 2021
Tweet

More Decks by notoroid

Other Decks in Programming

Transcript

  1. ॆిใࠂ͞Μ #BUUFSFDFJWFS w όοςϦʔϞχλʔ ϢʔςΟϦςΟʔ  w ࠷େ୆ ࣮ػ ϦϞʔτ୆

     w ख࣋ͪͷJ1IPOF͔Βଞʹ͍࣋ͬͯΔ J1IPOF J1BEͳͲͷػثͷόοςϦʔঢ়ଶ֬ ೝՄೳ w ࣗ୐ʹ͋ΔJ1IPOFͷόοςϦʔঢ়ଶ֬ೝՄ ೳ
  2. ॆిใࠂ͞Μ #BUUFSFDFJWFS w "QQMF8BUDIରԠ w $PNQMJDBUJPOTରԠ w ॆి׬ྃ௨஌ w ॆి׬ྃΛ఻͑ͯ͘ΕΔ௨஌Λ௥Ճ

    w ҎԼʹࢦఆ͢Δ͜ͱͰόοςϦʔΛέ Ξ͢Δ͜ͱ͕Մೳ w Կ͔ͱߴ͍J1IPOFΛ௕࣋ͪͤ͞Δͷʹ༗༻
  3. import SwiftUI struct ContentView: View { @State var myfield =

    "" @ScaledMetric(relativeTo: .body) var @ScaledMetric(relativeTo: .body) var @ScaledMetric(relativeTo: .body) var @ScaledMetric(relativeTo: .body) var var body: some View { VStack { Spacer() TextField("Label", text: $my .padding(EdgeInsets(top: .background( Rectangle() .stroke(Color.gr ) .padding() TextField("Label", text: $my .padding(EdgeInsets(top:
  4. import SwiftUI struct ContentView: View { @State var myfield =

    "" @ScaledMetric(relativeTo: .body) var @ScaledMetric(relativeTo: .body) var @ScaledMetric(relativeTo: .body) var @ScaledMetric(relativeTo: .body) var var body: some View { VStack { Spacer() TextField("Label", text: $my .padding(EdgeInsets(top: .background( Rectangle() .stroke(Color.gr ) .padding() TextField("Label", text: $my .padding(EdgeInsets(top:
  5. BWBJMBCMF JOMJOBCMF PCKD 6*"QQMJDBUJPO.BJO VOLOPXO EJTDBSEBCMF3FTVMU NBJO PCKD.FNCFST VTBCMF'SPN*OMJOF EZOBNJD$BMMBCMF

    OPOPCKD QSPQFSUZ8SBQQFS XBSO@VORVBMJ fi FE@BD DFTT EZOBNJD.FNCFS-P PLVQ /4"QQMJDBUJPO.BJO SFTVMU#VJMEFS BVUPDMPTVSF GSP[FO /4$PQZJOH SFRVJSFT@TUPSFE@QSP QFSUZ@JOJUT DPOWFOUJPO (,*OTQFDUBCMF /4.BOBHFE UFTUBCMF FTDBQJOH
  6. Bઌୡݴޠͱͷޓ׵ੑ w $ݴޠΛݺͼग़͠Մೳʹ 0CKFDUJF$Λݺͼग़͠Մೳʹ w ؔ਺ϙΠϯλͷޓ׵ੑࢦఆ !DPOWFOUJPO  w ໭Γ஋͕͋Δ͕ෆཁѻ͍ʹରԠ͢ΔͨΊ

    !EJTDBSEBCMF3FTVMU  w 0CKFDUJWF$ͷϓϩύςΟͷίϐʔଐੑରԠ !/4$PQZJOH  w NBJOؔ਺ͷӅṭ !6*"QQMJDBUJPO.BJO !/4"QQMJDBUJPO.BJO  w ϚϧνϓϥοτϑΥʔϜʹ΋ରԠͨ͠NBJOؔ਺ͷӅṭ !NBJO
  7. DϑϨʔϜϫʔΫ։ൃͷαϙʔτ w ϑϨʔϜϫʔΫར༻ऀʹඇਪ঑Ͱ͋Δ͜ͱΛࣔ͢(@available) w SwiftͰ࡞੒͞ΕͨϑϨʔϜϫʔΫ w ʙΛObjectie-C͔Βݺͼग़͠Մೳʹ(@objc) w ʙΛObjective-C͔Βݺͼग़͠ෆՄʹ(@nonobjc) w

    ʙΛObjective-C͔ΒҰׅͰݺͼग़͠Մೳʹ(@objcMembers) w τοϓϨϕϧͷΦϒδΣΫτ͕ଞϑϨʔϜϫʔΫͱࠞࡏΛආ͚Δ(@warn_unquali fi ed_access) w ໌ࣔతʹকདྷόʔδϣϯͰͷվมΛ੍ݶ͢Δ΋ͷ(@frozen)
  8. Bઌୡݴޠͱͷޓ׵ੑ w $ݴޠΛݺͼग़͠Մೳʹ 0CKFDUJF$Λݺͼग़͠Մೳʹ w ؔ਺ϙΠϯλͷޓ׵ੑࢦఆ !DPOWFOUJPO  w ໭Γ஋͕͋Δ͕ෆཁѻ͍ʹରԠ͢ΔͨΊ

    !EJTDBSEBCMF3FTVMU  w 0CKFDUJWF$ͷϓϩύςΟͷίϐʔଐੑରԠ !/4$PQZJOH  w NBJOؔ਺ͷӅṭ !6*"QQMJDBUJPO.BJO !/4"QQMJDBUJPO.BJO  w ϚϧνϓϥοτϑΥʔϜʹ΋ରԠͨ͠NBJOؔ਺ͷӅṭ !NBJO
  9. DϑϨʔϜϫʔΫ։ൃͷαϙʔτ w ϑϨʔϜϫʔΫར༻ऀʹඇਪ঑Ͱ͋Δ͜ͱΛࣔ͢(@available) w SwiftͰ࡞੒͞ΕͨϑϨʔϜϫʔΫ w ʙΛObjectie-C͔Βݺͼग़͠Մೳʹ(@objc) w ʙΛObjective-C͔Βݺͼग़͠ෆՄʹ(@nonobjc) w

    ʙΛObjective-C͔ΒҰׅͰݺͼग़͠Մೳʹ(@objcMembers) w τοϓϨϕϧͷΦϒδΣΫτ͕ଞϑϨʔϜϫʔΫͱࠞࡏΛආ͚Δ(@warn_unquali fi ed_access) w ໌ࣔతʹকདྷόʔδϣϯͰͷվมΛ੍ݶ͢Δ΋ͷ(@frozen)
  10. 4XJGU6*Ͱͷ4XJGU"UUSJCVUF w !SFTVMU#VJMEFS !@GVODUJPO#VJMEFS͔Β໊শมߋ  w 4XJGUͷ༧໿ޠɺฒͼ·Ͱؔ༩ 4XJGU6*্ͰͷJGจ  w

    هड़ϧʔϧΛڧ੍ 4XJGU6*Ͱ͸ݴޠͷ%4-Խʹ࢖༻  w هड़ΤϥʔΛίϯύΠϥϨϕϧͰิ଍Ͱ͖Δ w !QSPQFSUZ8SBQQFS w ม਺ʹ෇༩͢Δ4XJGU"UUSJCVUFΛ֦ு ಠࣗఆٛͷ௥Ճ  w 4XJGU6*Ͱ͸ม਺ͷମࡋΛอͪͭͭ୺తʹػೳ෇༩ʹ࢖༻
  11. struct ContentView: View { @State var isRounded = true //

    propertyWrapper // ViewͷBody͸1ͭͷView͔͠هड़Ͱ͖ͳ͍ var body: some View { // isRounded ʙ else ·Ͱ͸resultBuilderʹΑΔهड़ϧʔϧͰ͋ͬͯݴޠͷifจͱ͸ҟͳΔ // ৗʹܕ͸ҧ͏͕1ͭͷViewΛฦ͢ if isRounded { RoundedRectangle(cornerRadius: 20) .foregroundColor(.orange) .frame(width: 72, height: 72) .onTapGesture { isRounded = !isRounded } } else { Rectangle() .foregroundColor(.blue) .frame(width: 72, height: 72) .onTapGesture { isRounded = !isRounded } } } }
  12. struct ContentView: View { @State var isRounded = true //

    propertyWrapper // ViewͷBody͸1ͭͷView͔͠هड़Ͱ͖ͳ͍ var body: some View { // isRounded ʙ else ·Ͱ͸resultBuilderʹΑΔهड़ϧʔϧͰ͋ͬͯݴޠͷifจͱ͸ҟͳΔ // ৗʹܕ͸ҧ͏͕1ͭͷViewΛฦ͢ if isRounded { RoundedRectangle(cornerRadius: 20) .foregroundColor(.orange) .frame(width: 72, height: 72) .onTapGesture { isRounded = !isRounded } } else { Rectangle() .foregroundColor(.blue) .frame(width: 72, height: 72) .onTapGesture { isRounded = !isRounded } } } } !QSPQFSUZ8SBQQFS !SFTVMU#VJMEFS
  13. ࢀߟ w 4XJGUͷBUUSJCVUFશղઆʛશछ2JJUB w IUUQTRJJUBDPNTIUOLHNJUFNTDCBCDECD w "UUSJCVUFTŠ5IF4XJGU1SPHSBNNJOH-BOHVBHF 4XJGU  w

    IUUQTEPDTTXJGUPSHTXJGUCPPL3FGFSFODF.BOVBM"UUSJCVUFTIUNM w ʲ4XJGUʳ1SPQFSUZ8SBQQFSTͱ͸ʁc଎Ͱา͘ώτ w IUUQTXXXOEXBMLFSDPNTXJGUQSPQFSUZXSBQQFST w 'VODUJPO#VJMEFSͰ༡΅͏2JJUB w IUUQTRJJUBDPNUBSVOPOJUFNTFEBDDCE w 4XJGUͰ3FBDUJWF1SPHSBNNJOH2JJUB w IUUQTRJJUBDPNTIPIFJZPLPZBNBJUFNTBBBCE