Latest 1.0
Homepage https://github.com/freak4pc/SMWebView
License MIT
Platforms ios 8.0, requires ARC
Authors

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.

Latest podspec

{
    "name": "SMWebView",
    "version": "1.0",
    "summary": "SMWebView is a delightful, lightweight Swift wrapper around UIWebView that lets you harness the power of Closures and Chaining.",
    "description": "SMWebView is a delightful, lightweight Swift wrapper around UIWebView that lets you harness the power of Closures and Chaining. nAnd of course - Get rid of those pesky, awful delegates ;-)",
    "homepage": "https://github.com/freak4pc/SMWebView",
    "license": "MIT",
    "authors": {
        "freak4pc": "[email protected]"
    },
    "source": {
        "git": "https://github.com/freak4pc/SMWebView.git",
        "tag": "1.0"
    },
    "social_media_url": "http://i.imgur.com/1PFc32m.jpg",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This