12 Weeks as a iOS Developer Intern — Week Seven & Eight
Hello :D ! Week seven and eight was quite a busy whirlwind so I’ve combined it into one article. Here are some things I’ve learned during week seven and week eight~
Mocking Data
Sometimes features require data from the api that has not been yet up yet. For example when building a quantity stepper (enables user to increment/decrement quantity of an item), a maximum quantity is needed, for example a maximum quantity of 4 cups of chunky corn stew. Unless you have the capability to offer a huge amount of product like 400 cups of chunky corn stew, it is recommended to set a maximum quantity limit!
The maxQuantity property will be in the ProductOption object when the api has been set up. So naturally, I added an extension to ProductOption:
I found the last option the simplest for my use case. Just make sure to add a TODO comment to remind yourself that it’s a mock and to remove it once you get the real data. You don’t want to be pushing mock data into production 😅.
Update Constraints
SnapKit has a .makeConstraints for creating constraints. This week I discovered .updateConstraints. It does exactly as it’s name implies, it updates constraints. For example in a cell, if a product has an image, it should show the image by constraining the imageView height to the appropriate height. Whereas if the product does not have an image the imageView height should not show the imageView. The imageView height should be zero.
Remake Constraints
.updateConstraints updates specific constraints and leaves the others untouched. .remakeConstraints completely remakes the constraints in that it will use the new constraints and completely ignore the old constraints.
Animations
A product designer sent me an animation I had to make. I had to slightly shrink a viewControllerA’s contentCard into the foreground and have a child viewControllerB’s contentCard appear modally from the bottom of the screen at the same time. It was quite interesting to make. The animation also had to be timed correctly and was a bit finicky.
Firstly there’s no built in way to extend the duration of presenting a viewController modally. Presenting modally can also be faked by animating constraints. UIView.animate can be used to set duration.
customizationsContainerView.snp.updateConstraints { update in// top position of contentCardContaineris changed & animated which results in appearance of a modal presentationupdate.top.equalTo(contentCardContainer)}UIView.animate(withDuration: 0.2, delay: 0.1, options: [.curveEaseOut], animations: {self.view.layoutIfNeeded()}, completion: nil)
Tapping on the contentCard’s close button should enlarge the previously shrunken contentCard of viewControllerA back to it’s original size while simultaneously dismissing viewControllerB.
func closeButtonPressed() {customizationsContainerView.snp.updateConstraints { update inupdate.top.equalTo(contentCardContainer).offset(view.frame.size.height)}UIView.animate(withDuration: 0.3, animations: {//.identity sets the contentCard back to it's original sizeself.contentCard.transform = .identity}, completion: nil)UIView.animate(withDuration: 0.3, delay: 0.1, options: [.curveEaseOut], animations: {self.view.layoutIfNeeded()}, completion: nil)}
Thank you for reading!
Read about week six as an iOS developer intern here
Show your support with 👏 claps below, follow me on my iOS developer journey 😊 on Twitter