UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Helper method to convert view to Image now returns warning

Forums > SwiftUI

The helper method to convert a SwiftUI view to an image from here: https://www.hackingwithswift.com/quick-start/swiftui/how-to-convert-a-swiftui-view-to-an-image

With Xcode 14, this method sometimes returns a warning "Result of call to function returning 'Bool?' is unused".

The warning is tied to the return line: view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true)

The warning only appears sometimes - I'd say in every second build.

Why is this warning happening, and how to fix it?

1      

drawHierarchy returns a Bool. When you don't need the return value then

_ = view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true)

should fix this. Why it doesn't show the warning everytime I don't know. Perhaps a bug in Xcode.

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.