Skip to content

Commit df3e738

Browse files
committed
update for Swift 1.2, Xcode 6.3
1 parent 6f6b357 commit df3e738

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

bk2ch11p551webview/ch24p825webview/WebViewController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class WebViewController: UIViewController, UIWebViewDelegate, UIViewControllerRe
99
var canNavigate = false // distinguish the two examples, local and remote content
1010

1111
var wv : UIWebView {
12-
return self.view as UIWebView
12+
return self.view as! UIWebView
1313
}
1414

1515
required override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
@@ -21,7 +21,7 @@ class WebViewController: UIViewController, UIWebViewDelegate, UIViewControllerRe
2121
self.edgesForExtendedLayout = .None // get accurate offset restoration
2222
}
2323

24-
override convenience init() {
24+
convenience init() {
2525
self.init(nibName:nil, bundle:nil)
2626
}
2727

@@ -122,10 +122,10 @@ class WebViewController: UIViewController, UIWebViewDelegate, UIViewControllerRe
122122
case 1:
123123
let path = NSBundle.mainBundle().pathForResource("htmlbody", ofType:"txt")!
124124
let base = NSURL.fileURLWithPath(path)
125-
let ss = NSString(contentsOfFile:path, encoding:NSUTF8StringEncoding, error:nil)!
125+
let ss = String(contentsOfFile:path, encoding:NSUTF8StringEncoding, error:nil)!
126126

127127
let path2 = NSBundle.mainBundle().pathForResource("htmlTemplate", ofType:"txt")!
128-
var s = NSString(contentsOfFile:path2, encoding:NSUTF8StringEncoding, error:nil)!
128+
var s = String(contentsOfFile:path2, encoding:NSUTF8StringEncoding, error:nil)!
129129

130130
s = s.stringByReplacingOccurrencesOfString("<maximagewidth>", withString:"80%")
131131
s = s.stringByReplacingOccurrencesOfString("<fontsize>", withString:"18")
@@ -147,7 +147,7 @@ class WebViewController: UIViewController, UIWebViewDelegate, UIViewControllerRe
147147
let url = NSURL.fileURLWithPath(path)!
148148
self.wv.loadRequest(NSURLRequest(URL: url))
149149
case 4:
150-
let path = NSBundle.mainBundle().pathForResource("test", ofType:"rtf")! // works in simulator, blank on device :( "Cannot find data converter callback for uti public.rtf" [known issue, see release notes]
150+
let path = NSBundle.mainBundle().pathForResource("test", ofType:"rtf")! // works in simulator, works in device (iOS 8.3, I think it was fixed in 8.1)
151151
let url = NSURL.fileURLWithPath(path)!
152152
self.wv.loadRequest(NSURLRequest(URL: url))
153153
case 5:
@@ -171,7 +171,7 @@ class WebViewController: UIViewController, UIWebViewDelegate, UIViewControllerRe
171171
let url = NSURL.fileURLWithPath(path)!
172172
self.wv.loadRequest(NSURLRequest(URL: url))
173173
case 10:
174-
let path = NSBundle.mainBundle().pathForResource("test", ofType:"rtfd.zip")! // blank in simulator, blank on device, "Cannot find data converter callback for uti com.apple.rtfd"
174+
let path = NSBundle.mainBundle().pathForResource("test", ofType:"rtfd.zip")! // blank in simulator, blank on device, "Unable to read document" displayed
175175
let url = NSURL.fileURLWithPath(path)!
176176
self.wv.loadRequest(NSURLRequest(URL: url))
177177
case 11:
@@ -204,7 +204,7 @@ class WebViewController: UIViewController, UIWebViewDelegate, UIViewControllerRe
204204
}
205205

206206
func webView(webView: UIWebView, shouldStartLoadWithRequest r: NSURLRequest, navigationType nt: UIWebViewNavigationType) -> Bool {
207-
if r.URL.scheme == "play" {
207+
if let scheme = r.URL?.scheme where scheme == "play" {
208208
println("user would like to hear the podcast")
209209
return false
210210
}

bk2ch11p552webkit/ch24p825webview/WebViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class WebViewController: UIViewController, WKNavigationDelegate, WKScriptMessage
215215
s = s.stringByReplacingOccurrencesOfString("<content>", withString:ss)
216216

217217
// missing from docs, but in header file
218-
self.wv.loadHTMLString(s, baseURL:base) // fails because we can't load the local image
218+
self.wv.loadHTMLString(s, baseURL:base) // fails on device, because we can't load the local image
219219
// ===========================
220220
// so, WKWebView can't load _any_ files using a local file URL
221221
// but the other types work fine except for rtf / rtfd which is a known issue (see release notes)

bk2ch11p553webkit2/ch24p825webview/WebViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,19 @@ extension WebViewController : WKNavigationDelegate {
160160
println("did commit \(navigation)")
161161
}
162162

163-
func webView(webView: WKWebView, didFailNavigation navigation: WKNavigation, withError error: NSError!) {
163+
func webView(webView: WKWebView, didFailNavigation navigation: WKNavigation!, withError error: NSError) {
164164
println("did fail")
165165
}
166166

167-
func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation, withError error: NSError) {
167+
func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
168168
println("did fail provisional")
169169
}
170170

171-
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation) {
171+
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
172172
println("did finish")
173173
}
174174

175-
func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation) {
175+
func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
176176
println("did start")
177177
}
178178
}

0 commit comments

Comments
 (0)