Skip to content

Commit 5d72d36

Browse files
Swift 1.2 updates
1 parent 1eeed16 commit 5d72d36

File tree

2 files changed

+41
-40
lines changed

2 files changed

+41
-40
lines changed

YouTubePlayer/YouTubePlayer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
/* Begin PBXBuildFile section */
1010
50E5B9C91A4CAA050099BF69 /* YTPlayer.html in Resources */ = {isa = PBXBuildFile; fileRef = 50E5B9C81A4CAA050099BF69 /* YTPlayer.html */; };
11-
50E5B9CB1A4CAA150099BF69 /* VideoPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E5B9CA1A4CAA150099BF69 /* VideoPlayerView.swift */; };
11+
50E5B9CB1A4CAA150099BF69 /* YouTubePlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E5B9CA1A4CAA150099BF69 /* YouTubePlayer.swift */; };
1212
/* End PBXBuildFile section */
1313

1414
/* Begin PBXFileReference section */
1515
502AE85F1A475FD500306AD1 /* YouTubePlayer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = YouTubePlayer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1616
502AE8631A475FD500306AD1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = Info.plist; path = YouTubePlayer/Info.plist; sourceTree = "<group>"; };
1717
50E5B9C81A4CAA050099BF69 /* YTPlayer.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = YTPlayer.html; path = YouTubePlayer/YTPlayer.html; sourceTree = SOURCE_ROOT; };
18-
50E5B9CA1A4CAA150099BF69 /* VideoPlayerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VideoPlayerView.swift; path = YouTubePlayer/VideoPlayerView.swift; sourceTree = SOURCE_ROOT; };
18+
50E5B9CA1A4CAA150099BF69 /* YouTubePlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YouTubePlayer.swift; path = YouTubePlayer/YouTubePlayer.swift; sourceTree = SOURCE_ROOT; };
1919
/* End PBXFileReference section */
2020

2121
/* Begin PBXFrameworksBuildPhase section */
@@ -48,7 +48,7 @@
4848
502AE8611A475FD500306AD1 /* YouTubePlayer */ = {
4949
isa = PBXGroup;
5050
children = (
51-
50E5B9CA1A4CAA150099BF69 /* VideoPlayerView.swift */,
51+
50E5B9CA1A4CAA150099BF69 /* YouTubePlayer.swift */,
5252
50E5B9C81A4CAA050099BF69 /* YTPlayer.html */,
5353
502AE8621A475FD500306AD1 /* Supporting Files */,
5454
);
@@ -142,7 +142,7 @@
142142
isa = PBXSourcesBuildPhase;
143143
buildActionMask = 2147483647;
144144
files = (
145-
50E5B9CB1A4CAA150099BF69 /* VideoPlayerView.swift in Sources */,
145+
50E5B9CB1A4CAA150099BF69 /* YouTubePlayer.swift in Sources */,
146146
);
147147
runOnlyForDeploymentPostprocessing = 0;
148148
};

YouTubePlayer/YouTubePlayer/VideoPlayerView.swift renamed to YouTubePlayer/YouTubePlayer/YouTubePlayer.swift

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private extension NSURL {
6262
}
6363

6464
public func videoIDFromYouTubeURL(videoURL: NSURL) -> String? {
65-
return videoURL.queryStringComponents()["v"] as String?
65+
return videoURL.queryStringComponents()["v"] as? String
6666
}
6767

6868
/** Embed and control YouTube videos */
@@ -87,15 +87,13 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
8787
/** Used to respond to player events */
8888
public var delegate: YouTubePlayerDelegate?
8989

90-
// MARK: Various methods for initialization
9190

92-
override public init() {
93-
super.init()
94-
buildWebView(playerParameters())
95-
}
91+
// MARK: Various methods for initialization
9692

9793
override public init(frame: CGRect) {
9894
super.init(frame: frame)
95+
96+
printLog("initframe")
9997
buildWebView(playerParameters())
10098
}
10199

@@ -217,10 +215,10 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
217215

218216
// Check for error
219217
if let error = error {
220-
println("Lookup error: no HTML file found for path, \(path)")
218+
printLog("Lookup error: no HTML file found for path, \(path)")
221219
}
222220

223-
return htmlString!
221+
return htmlString! as String
224222
}
225223

226224

@@ -255,12 +253,12 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
255253

256254
// Check for error and return nil
257255
if let error = error {
258-
println("Error parsing JSON")
256+
printLog("Error parsing JSON")
259257
return nil
260258
}
261259

262260
// Success, return JSON string
263-
return NSString(data: jsonData!, encoding: NSUTF8StringEncoding)
261+
return NSString(data: jsonData!, encoding: NSUTF8StringEncoding) as? String
264262
}
265263

266264

@@ -271,38 +269,37 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
271269
// Grab the last component of the queryString as string
272270
let data: String? = eventURL.queryStringComponents()["data"] as? String
273271

274-
if let host = eventURL.host {
275-
if let event = YouTubePlayerEvents(rawValue: host) {
276-
// Check event type and handle accordingly
277-
switch event {
278-
case .YouTubeIframeAPIReady:
279-
ready = true
280-
break
272+
if let host = eventURL.host, let event = YouTubePlayerEvents(rawValue: host) {
273+
274+
// Check event type and handle accordingly
275+
switch event {
276+
case .YouTubeIframeAPIReady:
277+
ready = true
278+
break
281279

282-
case .Ready:
283-
delegate?.playerReady(self)
280+
case .Ready:
281+
delegate?.playerReady(self)
284282

285-
break
283+
break
286284

287-
case .StateChange:
288-
if let newState = YouTubePlayerState(rawValue: data!) {
289-
playerState = newState
290-
delegate?.playerStateChanged(self, playerState: newState)
291-
}
285+
case .StateChange:
286+
if let newState = YouTubePlayerState(rawValue: data!) {
287+
playerState = newState
288+
delegate?.playerStateChanged(self, playerState: newState)
289+
}
292290

293-
break
291+
break
294292

295-
case .PlaybackQualityChange:
296-
if let newQuality = YouTubePlaybackQuality(rawValue: data!) {
297-
playbackQuality = newQuality
298-
delegate?.playerQualityChanged(self, playbackQuality: newQuality)
299-
}
293+
case .PlaybackQualityChange:
294+
if let newQuality = YouTubePlaybackQuality(rawValue: data!) {
295+
playbackQuality = newQuality
296+
delegate?.playerQualityChanged(self, playbackQuality: newQuality)
297+
}
300298

301-
break
299+
break
302300

303-
default:
304-
break
305-
}
301+
default:
302+
break
306303
}
307304
}
308305
}
@@ -315,8 +312,12 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
315312
let url = request.URL
316313

317314
// Check if ytplayer event and, if so, pass to handleJSEvent
318-
if url.scheme == "ytplayer" { handleJSEvent(url) }
315+
if let url = url where url.scheme == "ytplayer" { handleJSEvent(url) }
319316

320317
return true
321318
}
322319
}
320+
321+
private func printLog(str: String) {
322+
println("[YouTubePlayer] \(str)")
323+
}

0 commit comments

Comments
 (0)