blog
blog copied to clipboard
π What you don't know is what you haven't learned
In some case, we should not use base type like `UTType.text` but to be more specific like `UTType.utf8PlainText` ```swift import UniformTypeIdentifiers var dropTypes: [UTType] { [ .fileURL, .url, .utf8PlainText, .text...
Use underscore `_focus` we get access to underlying `FocusState` object, but underscore `_` is private to a View hence can't be used in extension If we want to pass FocusState...
Use `NSTextAttachment` inside `NSAttributedString` ```swift extension UILabel { func addTrailing(image: UIImage) { let attachment = NSTextAttachment() attachment.image = image let attachmentString = NSAttributedString(attachment: attachment) let string = NSMutableAttributedString(string: self.text!, attributes:...
Apply `.move` on `reversed` array ```swift List(selection: $viewModel.selectedBook) { ForEach(viewModel.books.reversed()) { book in BookCell(book: book) } .onMove { source, dest in var reversed = Array(viewModel.books.reversed()) reversed.move(fromOffsets: source, toOffset: dest) viewModel.books...
Use CoreImage to generate QR image ```swift import SwiftUI import CoreImage.CIFilterBuiltins struct QRView: View { let qrCode: String @State private var image: UIImage? var body: some View { ZStack {...
Use a `UIView` as source view and set it in background ```swift class ViewModel { lazy var sourceView = UIView() } struct SourceView: UIViewRepresentable { let viewModel: ViewModel func makeUIView(context:...
Interesting SwiftUI Q&A during WWDC22 ### Whatβs the difference between a custom ViewModifier vs View extension Q: Whatβs the difference between a custom ViewModifier (without DynamicProperty) that uses some built-in...
Specify optional value for `List(selection:)`. This keeps selection on macOS, but not on iPad. On iPad each row in the List needs to be `NavigationLink`, no need for `.tag`. The...
- [Objcio Swift Talk](https://talk.objc.io/) - [Hacking With Swift](https://www.hackingwithswift.com/) - [AppCoda](https://www.appcoda.com/) - [Swift by Sundell](https://swiftbysundell.com/) - [Swift with Majid](https://swiftwithmajid.com/) - [Nil Coalescing](https://nilcoalescing.com/)
Below are my favorite WWDC videos. My focus is to use SwiftUI to make useful apps with great UX. I don't pay much attention to new frameworks as they come...