Share
Embed
Transcript
51 slides
-
1 ϩδοΫΛΉ 2 StoryboardͰϨΠΞτ 3 ಈ࡞֬ೝ w ͦΕͧΕͷΞʔΩςΫνϟʹԠͯ͡ϩδοΫ͔ΒΜͰ͍͘ w $MFBO"SDIJUFDUVSFͳΒ%PNBJO͔Β
w ςετॻ͘ w ΞχϝʔγϣϯͳͲಈతͳཁૉҎ֎ఆٛͯ͠͠·͏ w ࣮ػ4JNVMBUPSͰҙਤͨ͠ڍಈΛ͢Δ͔֬ೝ -
1 ϩδοΫΛΉ 2 StoryboardͰϨΠΞτ 3 ಈ࡞֬ೝ w ͦΕͧΕͷΞʔΩςΫνϟʹԠͯ͡ϩδοΫ͔ΒΜͰ͍͘ w $MFBO"SDIJUFDUVSFͳΒ%PNBJO͔Β
w ςετॻ͘ w ΞχϝʔγϣϯͳͲಈతͳཁૉҎ֎ఆٛͯ͠͠·͏ w ࣮ػ4JNVMBUPSͰҙਤͨ͠ڍಈΛ͢Δ͔֬ೝ 4 σβΠϯௐ -
1 ϩδοΫΛΉ 2 StoryboardͰϨΠΞτ 3 ಈ࡞֬ೝ w ͦΕͧΕͷΞʔΩςΫνϟʹԠͯ͡ϩδοΫ͔ΒΜͰ͍͘ w $MFBO"SDIJUFDUVSFͳΒ%PNBJO͔Β
w ςετॻ͘ w ΞχϝʔγϣϯͳͲಈతͳཁૉҎ֎ఆٛͯ͠͠·͏ w ࣮ػ4JNVMBUPSͰҙਤͨ͠ڍಈΛ͢Δ͔֬ೝ 4 σβΠϯௐ ͕݁͜͜ߏਏ͍… -
Xcode Simulator /Device #VJME͕௨ΔͷΛͬͯ ϨΠΞτΛ֬ೝ ϨΠΞτΛௐͯ͠ ࠶Ϗϧυ • ෳղ૾ͰͷϨΠΞτ •
݅ʹΑͬͯมΘΔදࣔ༰ • ϩʔΧϥΠζͷจݴ… -
What’s new in Playground - WWDC 2018 Xcode10͔ΒPlaygroundͷஞ࣮࣍ߦ͕Մೳʹ…!! (https://developer.apple.com/videos/play/ wwdc2018/402/)
Alex Brown, Core OS Engineer • Running Step by Step NEW -
What’s new in Playground - WWDC 2018 ҰʑίϝϯτΞτ͢Δඞཁ͕ͳ͘ ϑϩʔΛڞ௨Խ͘͢͠ͳͬͨ Alex
Brown, Core OS Engineer • Running Step by Step NEW -
DEMOͷྲྀΕ • TwitterͷΑ͏ͳΞϓϦΛ࡞ͬͨʂ • σβΠϯ֬ೝ͢Δͧʂ ߘ͕ ͳ͍/͋Δ ͱ͖ͷදࣔਖ਼͍͠ʁ ͪΌΜͱ ϩʔΧϥΠζ
͞ΕͯΔʁ খ͍͞, େ͖͍Ͱ ϨΠΞτ ่Εͯͳ͍ʁ • मਖ਼ͯ͠ View͚ͩ ϏϧυͰ࠶֬ೝʂ -
func display(device: Device, orientation: Orientation, language: Language) { let vc
= R.storyboard.twitter.instantiateInitialViewController()! let (parent, _) = playgroundControllers(device: device, orientation: .portrait, child: vc) AppEnvironment.language = language PlaygroundPage.current.liveView = parent vc.load(statuses) } 1SPKFDUQMBZHSPVOE5XJUUFSYDQMBZHSPVOEQBHF -
func display(device: Device, orientation: Orientation, language: Language) { let vc
= R.storyboard.twitter.instantiateInitialViewController()! let (parent, _) = playgroundControllers(device: device, orientation: .portrait, child: vc) AppEnvironment.language = language PlaygroundPage.current.liveView = parent vc.load(statuses) } 1SPKFDUQMBZHSPVOE5XJUUFSYDQMBZHSPVOEQBHF -
1SPKFDUQMBZHSPVOE5XJUUFSYDQMBZHSPVOEQBHF func display(device: Device, orientation: Orientation, language: Language) { let
vc = R.storyboard.twitter.instantiateInitialViewController()! let (parent, _) = playgroundControllers(device: device, orientation: .portrait, child: vc) AppEnvironment.language = language PlaygroundPage.current.liveView = parent vc.load(statuses) } simulatorͷsizeͳͲΛࢦఆ -
public func playgroundControllers(device: Device = .phone4_7inch, orientation: Orientation, child: UIViewController,
additionalTraits: UITraitCollection) -> (parent: UIViewController, child: UIViewController) { let parent = UIViewController() parent.addChild(child) parent.view.addSubview(child.view) child.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] let traits: UITraitCollection switch (device, orientation) { case (.phone3_5inch, .portrait): parent.view.frame = .init(x: 0, y: 0, width: 320, height: 480) traits = .init(traitsFrom: [ .init(horizontalSizeClass: .compact), .init(verticalSizeClass: .regular), .init(userInterfaceIdiom: .phone) ]) ɾ ɾ ɾ simulatorͷsizeͳͲΛࢦఆ 1SPKFDUQMBZHSPVOE4PVSDFTEFWJDFTXJGU -
public func playgroundControllers(device: Device = .phone4_7inch, orientation: Orientation, child: UIViewController,
additionalTraits: UITraitCollection) -> (parent: UIViewController, child: UIViewController) { let parent = UIViewController() parent.addChild(child) parent.view.addSubview(child.view) child.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] let traits: UITraitCollection switch (device, orientation) { case (.phone3_5inch, .portrait): parent.view.frame = .init(x: 0, y: 0, width: 320, height: 480) traits = .init(traitsFrom: [ .init(horizontalSizeClass: .compact), .init(verticalSizeClass: .regular), .init(userInterfaceIdiom: .phone) ]) 1SPKFDUQMBZHSPVOE4PVSDFTEFWJDFTXJGU ɾ ɾ ɾ simulatorͷsizeͳͲΛࢦఆ Device, OrientationʹԠͯ͡ sizeΛࢦఆ͢Δ -
ɾ ɾ ɾ child.view.frame = parent.view.frame parent.preferredContentSize = parent.view.frame.size parent.view.backgroundColor
= .white child.view.backgroundColor = .white let allTraits = UITraitCollection.init(traitsFrom: [traits, additionalTraits]) parent.setOverrideTraitCollection(allTraits, forChild: child) return (parent, child) } simulatorͷsizeͳͲΛࢦఆ 1SPKFDUQMBZHSPVOE4PVSDFTEFWJDFTXJGU -
ɾ ɾ ɾ child.view.frame = parent.view.frame parent.preferredContentSize = parent.view.frame.size parent.view.backgroundColor
= .white child.view.backgroundColor = .white let allTraits = UITraitCollection.init(traitsFrom: [traits, additionalTraits]) parent.setOverrideTraitCollection(allTraits, forChild: child) return (parent, child) } simulatorͷsizeͳͲΛࢦఆ 1SPKFDUQMBZHSPVOE4PVSDFTEFWJDFTXJGU preferredContentSizeΛࢦఆ͢Δ͜ͱͰ Playground্Ͱදࣔ͢ΔViewͷେ͖͞ΛมߋՄೳ -
func display(device: Device, orientation: Orientation, language: Language) { let vc
= R.storyboard.twitter.instantiateInitialViewController()! let (parent, _) = playgroundControllers(device: device, orientation: .portrait, child: vc) AppEnvironment.language = language PlaygroundPage.current.liveView = parent vc.load(statuses) } 1SPKFDUQMBZHSPVOE5XJUUFSYDQMBZHSPVOEQBHF -
func display(device: Device, orientation: Orientation, language: Language) { let vc
= R.storyboard.twitter.instantiateInitialViewController()! let (parent, _) = playgroundControllers(device: device, orientation: .portrait, child: vc) AppEnvironment.language = language PlaygroundPage.current.liveView = parent vc.load(statuses) } 1SPKFDUQMBZHSPVOE5XJUUFSYDQMBZHSPVOEQBHF LanguageΛࢦఆ -
public struct AppEnvironment { public static var language: Language =
.ja public static var currentUser: String? = nil public var isLoggedIn: Bool { return AppEnvironment.currentUser != nil } } GlobalʹΞϓϦͷڥΛ͍࣋ͨͤͯΔ LanguageΛࢦఆ %PNBJO"QQ&OWJSPONFOUTXJGU -
extension StringResourceType { func localized(language: Language = AppEnvironment.language) -> String
{ return NSLocalizedString(key, bundle: Bundle(path: stringsBundle.path(forResource: language.rawValue, ofType: "lproj") ?? "") ?? stringsBundle, comment: "") } } private class Pin {} public let stringsBundle = Bundle(for: Pin.self) LanguageΛࢦఆ 1SFTFOUBUJPOʜ4USJOH3FTPVSDF5ZQF MPDBMJ[FETXJGU -
extension StringResourceType { func localized(language: Language = AppEnvironment.language) -> String
{ return NSLocalizedString(key, bundle: Bundle(path: stringsBundle.path(forResource: language.rawValue, ofType: "lproj") ?? "") ?? stringsBundle, comment: "") } } private class Pin {} public let stringsBundle = Bundle(for: Pin.self) 1SFTFOUBUJPOʜ4USJOH3FTPVSDF5ZQF MPDBMJ[FETXJGU NSLocalizedStringͷҾʹ LanguageʹԠͨ͡BundleΛ͢Α͏ʹ͢Δ LanguageΛࢦఆ -
func display(device: Device, orientation: Orientation, language: Language) { let vc
= R.storyboard.twitter.instantiateInitialViewController()! let (parent, _) = playgroundControllers(device: device, orientation: .portrait, child: vc) AppEnvironment.language = language PlaygroundPage.current.liveView = parent vc.load(statuses) } 1SPKFDUQMBZHSPVOE5XJUUFSYDQMBZHSPVOEQBHF -
func display(device: Device, orientation: Orientation, language: Language) { let vc
= R.storyboard.twitter.instantiateInitialViewController()! let (parent, _) = playgroundControllers(device: device, orientation: .portrait, child: vc) AppEnvironment.language = language PlaygroundPage.current.liveView = parent vc.load(statuses) } 1SPKFDUQMBZHSPVOE5XJUUFSYDQMBZHSPVOEQBHF Playground্ͰViewΛදࣔͯ͠ Cellʹදࣔ͢ΔߘΛಡΈࠐΉ