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

What's the difference between UIWebView and WKWebView?

Swift version: 5.6

Paul Hudson    @twostraws   

The UIWebView class has been around since iOS 2.0 as a way to show HTML content inside your app, but iOS 8.0 introduced WKWebView as an alternative - what's the difference?

Well, there are several differences, but two are particularly important. First, UIWebView is part of UIKit, and thus is available to your apps as standard. You don't need to import anything – it's just there. This also means it's available inside Interface Builder, so you can drag and drop web view into your designs.

Second, WKWebView is run in a separate process to your app so that it can draw on native Safari JavaScript optimizations. This means WKWebView loads web pages faster and more efficiently than UIWebView, and also doesn't have as much memory overhead for you.

In iOS 8.0 WKWebView was unable to load local files, but this got fixed in iOS 9.0. The main reason to use UIWebView nowadays is for access to older features such as "Scale pages to fit" - this is not available in WKWebView.

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!

Available from iOS 8.0 – see Hacking with Swift tutorial 4

Similar solutions…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 2.6/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.