TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Shai Mishali.
SMWebView is a delightful, lightweight Swift wrapper around UIWebView that lets you harness the power of Closures and Chaining. And of course - Get rid of those pesky, awful delegates ;-)
Instead of allocating a new UIWebView and assigning a delegate to it, you can use either a Storyboard or SMWebView’s static methods in order to get started.
Using a storyboard setup is as easy as calling loadURL
/ loadHTML
on our SMWebView Outlet, which will put all of this closure-chaining magic is right at your finger tips :)
@IBOutlet weak fileprivate var webView: SMWebView!
...
// Basic Implementation
webView
.loadURL(URL(string: "https://github.com/freak4pc")!)
.didCompleteLoading { webView in
print("Finished loading entire webpage")
}
// All Options
webView
.loadURL(URL(string: "https://github.com/freak4pc")!)
.didStartLoading { webView in
print("Started loading \(webView.request?.url?.absoluteString)")
}
.didFinishLoading { webView in
print("Finished loading \(webView.request?.url?.absoluteString)")
}
.didFailLoading { webView, error in
print("Failed loading \(error)")
}
.didCompleteLoading { webView in
print("Finished loading entire webpage")
}
.shouldStartLoading { webView, request, type in
return true
}
SMWebView features Static Methods allowing you to configure your entire SMWebView with a single statement, followed by setting the frame and adding it to your view hierarchy as follows:
let webView = SMWebView
.loadURL(URL(string: "https://github.com/freak4pc")!)
.didCompleteLoading { webView in
print("Finished loading URL: \(webView.request?.url?.absoluteString)")
}
webView.frame = UIScreen.main.bounds
self.view.addSubview(webView)
Clearly all other options from the Storyboard example are relevant here as well.
SMWebView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SMWebView'
Shai Mishali (freak4pc)
SMWebView is available under the MIT license. See the LICENSE file for more info.