[go: up one dir, main page]

Skip to content

Swift implementation for UIWebView with Closures instead of pesky annoying delegates ;)

License

Notifications You must be signed in to change notification settings

freak4pc/SMWebView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SMWebView

Version License Platform

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 ;-)

Usage

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.

Storyboard / Outlet Usage

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
    }
Classic Usage

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.

Installation

SMWebView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SMWebView'

Author

GitHub Twitter Facebook

Shai Mishali (freak4pc)

License

SMWebView is available under the MIT license. See the LICENSE file for more info.

About

Swift implementation for UIWebView with Closures instead of pesky annoying delegates ;)

Resources

License

Stars

Watchers

Forks

Packages

No packages published