Mastering SwiftUI: Using onChange, ContentUnavailableView, ShareLink, and Core Image for Dynamic User Interactions

Swift topics studied today included onChange, ContentUnavailableView, ShareLink, and Core Image. These tools combined with others helped me complete the task of allowing users to upload their own images, apply filters, and share them with friends.

Property wrappers manage state internally, bypassing setters. onChange is a solution to track state for property observers on property wrappers. Normally, with property wrappers, the setter is bypassed by changing the value directly, leaving the property observer to watch for a change that only happens internally. For the property observer to work, it needs to happen externally.

ContentUnavailableView is useful when your app relies on user information but hasn't been provided yet. It basically serves as a place holder that takes a a name, optional systemImage, and description as parameters.

ShareLink is a helpful SwiftUI component. It allows you to share data across apps if the app is compatible. It needs an item, optional subject, and optional message. You can also create your own customized button with a preview as well.

Core Image is a framework that allows you to manipulate images. It's quite the task to integrate it with SwiftUI. You'll need wrap an optional Image view with @State, resize it to fill the screen, use an onAppear modifier, and create a loadImage method. In this method you'll need typecast the image as a UI Image then to a CI image, import CoreImage & CoreImage.CIFilterBuiltins. From there you can create a context in your method and add a filter.
hashtag#hackingwithswift

Previous
Previous

"Exploring MapKit: Customizing Maps and Camera Views in SwiftUI"

Next
Next

Bridging Data Gaps: Combining Astronaut and Mission Data with Swift Structs