blog icon indicating copy to clipboard operation
blog copied to clipboard

🍁 What you don't know is what you haven't learned

Results 195 blog issues
Sort by recently updated
recently updated
newest added

Declare `EnvironmentKey` and read `safeAreaInsets` from key window in `connectedScenes` ```swift struct SafeAreaInsetsKey: EnvironmentKey { static var defaultValue: EdgeInsets { UIApplication.shared.keyWindow?.safeAreaInsets.swiftUIInsets ?? EdgeInsets() } } private extension UIEdgeInsets { var...

swift
swiftUI

Declare generic on `RawRepresentable` ```swift import SwiftUI struct TabStrip: View where T.RawValue == String { let values: [T] @Binding var selected: T var body: some View { ScrollView(.horizontal, showsIndicators: false)...

swift
swiftUI

One seemingly obvious way to use ForEach on array with indices is using `enumerated` ```swift struct Book: Hashable, Identifiable { let id: UUID let name: String } struct BooksView: View...

swift
swiftUI

Used to replace credit card regex `30[0-5]#-######-###L` in [EasyFake](https://github.com/onmyway133/EasyFake) We can use `?` to have non-greedy behavior, or I here use square bracket to fine-tune the expression `\{[\d*,]*\d*\}` Also, I...

swift

Use locales data from `faker.js` to https://github.com/onmyway133/EasyFake, renaming files since files, regardless of sub directories in Xcode, must have different name. We use `enumerator` API on `FileManager` to traverse all...

swift

I usually use `GeometryReader` in `background` to get size of view, and encapsulate it inside a `ViewModifier` ```swift struct GetHeightModifier: ViewModifier { @Binding var height: CGFloat func body(content: Content) ->...

swift
swiftUI

If we have a Picker inside a View that has DragGesture, chances are when we scroll the wheel, the DragGesture is detected too To prevent this, we can attach a...

swift
swiftUI

In iOS 15, we can use `UISheetPresentationController` to show bottom sheet like native Maps app. But before that there's no such built in bottom sheet in UIKit or SwiftUI. We...

swift
swiftUI

I usually define `ButtonStyle` to encapsulate common styles related to buttons. Here we specify ` .frame(maxWidth: .infinity)` to let this button take the whole width as possible ```swift struct MyActionButtonStyle:...

iOS
swift
swiftUI