View profile

 iOS Code Review | Curated code improvement tips - Issue #20

 iOS Code Review
 iOS Code Review
Hi there,
Can’t believe this is already the 20th issue 🎉 A milestone for sure. Thank you for your continuous support and feedback - and for spreading the word!

Old new UIKit APIs
When new APIs are introduced at WWDC, we can’t use them right away in apps supporting previous iOS versions. And when the time comes, we already forgot about them.
@onmyway133 shares a collection of reminders about cool and useful APIs that were introduced in previous years:
Khoa 🔥
UIViewPropertyAnimator, iOS 10

UIView.animate is as old as iOS 4. From iOS 10, you should use UIViewPropertyAnimator which animates changes to views and allows the dynamic modification of those animations.

It allows fine-grain control over progress and support cancellation. https://t.co/Fmz1MZu07s
Khoa 🔥
UIStackView.customSpacing, iOS 11

UIStackView has had spacing since its debut in iOS 9, but only after iOS 11 had we have the ability to have custom spacing https://t.co/3kwuuM1gfR
Khoa 🔥
UITextContentType, iOS 12

Do you prefer iOS itself to keep your passwords?

Text content type, providing semantic meaning for a text-entry area, is from iOS 10.

From iOS 12, you can specify .newPassword and password rules for AutoFill to kick in in your password text field. https://t.co/2TwbEzRE1r
Khoa 🔥
UITabBarApperance, iOS 13

There were UITabBar.appearance() and UITabBar, but with the introduction of dark mode in iOS 13 and to better unifying tabbar customization, the preferred method is to use UITabBarApperance

There are 4 states: normal, selected, focused, disabled https://t.co/ahDUWIe8pH
Khoa 🔥
keyboardDismissMode, iOS 7

Have you tried making the keyboard dismissal follow along drag gesture? It's not an easy feast but I still see manual implementation in some codebases.

They didn't know that in iOS 7, you can specify keyboardDismissMode to be .interactive. https://t.co/jHPAF5oCnU
Array slice indices
The fact that a slice is just a “view” into the original array can be unexpected and lead to indexing bugs. Convert to the slice to Array(slice) to avoid this, though then new memory will be used.
Joshua Bryson
Whoa! Array slices have the same indices as their array:

let array = [1,2,3,4]

let slice = array[1...]
slice[0] // out of bounds!
#Swift #SwiftLang
Int vs UInt
Turns out, the official Swift documentation recommends against using UInt for simply noting values that shouldn’t be negative:
A consistent use of Int for integer values aids code interoperability, avoids the need to convert between different number types, and matches integer type inference, as described in Type Safety and Type Inference.
Ben Gilroy
@manuelmaly It is mentioned as a note in Swift docs that using Int even when you know values will always be non-negative aids code interoperability. Although it doesn’t specifically mention Array.count.
https://t.co/eUQcmlkleR https://t.co/WrmWHI0T1O
On software design
Have you heard of the broken windows theory? In short, it says that when there’s a broken window on a building, more windows will get broken there. One graffiti attracts more graffiti. This is a fairly short article, that nonetheless brings an interesting perspective to the topic of software design and maintenance.
Apply "Broken-Windows" theory to the Software Design
Did you enjoy this issue? Yes No
 iOS Code Review
 iOS Code Review @ios_code_review

Bi-weekly newsletter amplifying code improvement tips from the Apple developer community. Swift, Objective-C, iOS, macOS, SwiftUI, UIKit and more. Curated by Marina Gornostaeva and published every other Thursday.

In order to unsubscribe, click here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Created with Revue by Twitter.