Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When can I remove convertToUIApplicationOpenExternalURLOptionsKeyDictionary helper function?

Tags:

ios

swift

When I migrated to Swift 4.2 last year, Swift 4.2 migrator added a helper function in some of my controllers:

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(_ input: [String: Any]) -> [UIApplication.OpenExternalURLOptionsKey: Any] {
    return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)})
}

When is it safe to remove?

like image 934
Glenn Posadas Avatar asked Feb 01 '19 17:02

Glenn Posadas


1 Answers

Presumably, some function in that file (or in a prior version of the file) calls this UIApplication method:

func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any] = [:], completionHandler completion: ((Bool) -> Void)? = nil)

Prior to iOS 12, the method had a different signature:

func open(_ url: URL, options: [String : Any] = [:], completionHandler completion: ((Bool) -> Void)? = nil)

When Xcode 10 migrated your project, it added the convertToUIApplicationOpenExternalURLOptionsKeyDictionary function and inserted a call to that function in each call to the open(_:options:completionHandler:) method to translate the options dictionary.

If you update each call to the open(_:options:completionHandler:) method to use the UIApplication.OpenExternalURLOptionsKey constants, you can remove the calls to convertToUIApplicationOpenExternalURLOptionsKeyDictionary and remove the function entirely.

like image 126
rob mayoff Avatar answered Sep 29 '22 01:09

rob mayoff