Hey! The starter projects, and all the projects in this course, are built with Swift 4.2 on Xcode 10 and iOS 12. So the reason the project won’t build is because Swift 4.2 introduced a couple of changes.
UIApplicationLaunchOptionsKey changed to UIApplication.LaunchOptionsKey and UIScrollViewDecelerationRateFast changed to UIScrollView.DecelerationRate.fast
If you change them back to the original, the project should compile fine. Sorry about that!
Just to clarify, the projects as they are are built for 4.2 Swift where UIApplication.LaunchOptionsKey and UIScrollView.DecelerationRate.fast are used.
For projects build with earlier Swift versions you should use UIApplicationLaunchOptionsKey and UIScrollViewDecelerationRateFast.
We’re adding the gesture recognizers because we’re passing through an UIView touches to the scroll view, and by adding the tap gesture recognizers to the buttons, we can still capture those touches on the buttons themselves.
// add view controllers as children
for (index, controller) in viewControllers.enumerated() {
if let controller = controller {
addChild(controller)
controller.view.frame = frame(for: index)
scrollView.addSubview(controller.view)
controller.didMove(toParent: self)
}
}
// add view controllers as children
for (index, controller) in viewControllers.enumerated() {
if let controller = controller {
addChildViewController(controller)
controller.view.frame = frame(for: index)
scrollView.addSubview(controller.view)
controller.didMove(toParentViewController: self)
}
}
Hi @lac_ekim the above code sample should work for you
I think that doesn’t work because you’re not using Xcode 10 + Swift 4.2 - the tools used to build this course. @markohara gave the correct solution for earlier versions - I hope it worked for you!
How does the scrollView get its dimensions? when instantiated it is 0.0 0.0 0.0 0.0, in viewDidAppear it has the right dimensions, I thought you would need constraints for something like that to happen.
This is what confuses me, because pageSize property uses the scrollView itself, at some point the width of the scrollView change from 0 to 375, and I can’t find where that is.
In the loadView function, we set the scrollView to be the view like this view = scrollView. Which gives the scrollView that initial frame. So when we grab the pageSize in viewDidAppear to set the scrollView’s contentSize the pageSize will return the correct size.