Permalink
Browse files

SwiftLint compliance

  • Loading branch information...
1 parent b09f5fc commit ad50032c98cffb1896361e5a9d6f785fdcd22d4c @JohnCoates committed Sep 23, 2016
View
@@ -0,0 +1,13 @@
+disabled_rules:
+ - trailing_whitespace
+ - force_cast
+ - function_body_length
+ - type_body_length
+ - file_length
+
+variable_name:
+ min_length:
+ warning: 2
+ error: 2
+line_length:
+ warning: 120
@@ -237,6 +237,7 @@
isa = PBXNativeTarget;
buildConfigurationList = FA143CE01BDA3E880041A82B /* Build configuration list for PBXNativeTarget "Aerial Test" */;
buildPhases = (
+ FA74B8481D94DCE0004FE056 /* ShellScript */,
FA143CD21BDA3E880041A82B /* Sources */,
FA143CD31BDA3E880041A82B /* Frameworks */,
FA143CD41BDA3E880041A82B /* Resources */,
@@ -334,6 +335,22 @@
};
/* End PBXResourcesBuildPhase section */
+/* Begin PBXShellScriptBuildPhase section */
+ FA74B8481D94DCE0004FE056 /* ShellScript */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
+ };
+/* End PBXShellScriptBuildPhase section */
+
/* Begin PBXSourcesBuildPhase section */
FA143CD21BDA3E880041A82B /* Sources */ = {
isa = PBXSourcesBuildPhase;
@@ -34,16 +34,16 @@ class City {
if timeOfDay.lowercased() == "night" {
video.arrayPosition = night.videos.count
night.videos.append(video)
- }
- else {
+ } else {
video.arrayPosition = day.videos.count
day.videos.append(video)
}
}
}
@objc(PreferencesWindowController)
-class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource, NSOutlineViewDelegate, VideoDownloadDelegate {
+class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
+NSOutlineViewDelegate, VideoDownloadDelegate {
@IBOutlet var outlineView: NSOutlineView!
@IBOutlet var playerView: AVPlayerView!
@@ -113,7 +113,7 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
let color = NSColor(calibratedRed: 0.18, green: 0.39, blue: 0.76, alpha: 1)
let link = projectPageLink.attributedTitle
let coloredLink = NSMutableAttributedString(attributedString: link)
- let fullRange = NSMakeRange(0, coloredLink.length)
+ let fullRange = NSRange(location: 0, length: coloredLink.length)
coloredLink.addAttribute(NSForegroundColorAttributeName,
value: color,
range: fullRange)
@@ -217,7 +217,7 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
// MARK: - Manifest
func loadJSON() {
- if (PreferencesWindowController.loadedJSON) {
+ if PreferencesWindowController.loadedJSON {
return
}
PreferencesWindowController.loadedJSON = true
@@ -244,7 +244,6 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
videos.append(video)
}
-
self.videos = videos
// sort cities by name
@@ -314,10 +313,9 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
case is City:
let city = item as! City
- if (index == 0 && city.day.videos.count > 0) {
+ if index == 0 && city.day.videos.count > 0 {
return city.day
- }
- else {
+ } else {
return city.night
}
@@ -330,7 +328,8 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
}
}
- func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
+ func outlineView(_ outlineView: NSOutlineView,
+ objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
switch item {
case is City:
let city = item as! City
@@ -418,7 +417,6 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
view.checkButton.state = NSOffState
}
-
view.onCheck = { checked in
self.preferences.setVideo(videoID: video.id,
inRotation: checked)
@@ -445,7 +443,6 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
player.replaceCurrentItem(with: item)
player.play()
-
return true
case is TimeOfDay:
return false
@@ -498,7 +495,6 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
return video.isAvailableOffline == false
}
-
if uncached.count == 0 {
cacheStatusLabel.stringValue = "All videos have been cached"
return
@@ -510,7 +506,6 @@ class PreferencesWindowController: NSWindowController, NSOutlineViewDataSource,
totalProgress.doubleValue = Double(manifestVideos.count) - Double(uncached.count)
NSLog("total process max value: \(totalProgress.maxValue), current value: \(totalProgress.doubleValue)")
-
let video = uncached[0]
// find video that hasn't been cached
@@ -8,7 +8,6 @@
import Foundation
-
class AerialVideo {
let id: String
let name: String
@@ -25,7 +24,6 @@ class AerialVideo {
}
}
-
init(id: String, name: String, type: String,
timeOfDay: String, url: String) {
self.id = id
@@ -22,8 +22,7 @@ func CachedOrCachingAsset(_ URL: Foundation.URL) -> AVURLAsset {
return asset
}
-
-class AssetLoaderDelegate : NSObject, AVAssetResourceLoaderDelegate, VideoLoaderDelegate {
+class AssetLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, VideoLoaderDelegate {
let URL: Foundation.URL
var videoLoaders: [VideoLoader] = []
@@ -56,7 +55,8 @@ class AssetLoaderDelegate : NSObject, AVAssetResourceLoaderDelegate, VideoLoader
}
// MARK: - Asset Resource Loader Delegate
- func resourceLoader(_ resourceLoader: AVAssetResourceLoader, didCancel loadingRequest: AVAssetResourceLoadingRequest) {
+ func resourceLoader(_ resourceLoader: AVAssetResourceLoader,
+ didCancel loadingRequest: AVAssetResourceLoadingRequest) {
// debugLog("cancelled load request: \(loadingRequest)")
var remove: VideoLoader?
@@ -80,7 +80,9 @@ class AssetLoaderDelegate : NSObject, AVAssetResourceLoaderDelegate, VideoLoader
}
}
- func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
+ func resourceLoader(_ resourceLoader: AVAssetResourceLoader,
+ shouldWaitForLoadingOfRequestedResource
+ loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
// check if cache can fulfill this without a request
if videoCache.canFulfillLoadingRequest(loadingRequest) {
@@ -10,7 +10,6 @@ import Foundation
import AVFoundation
import ScreenSaver
-
class VideoCache {
var videoData: Data
var mutableVideoData: NSMutableData?
@@ -48,9 +47,9 @@ class VideoCache {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: appCacheDirectory as String) == false {
do {
- try fileManager.createDirectory(atPath: appCacheDirectory as String, withIntermediateDirectories: false, attributes: nil)
- }
- catch let error {
+ try fileManager.createDirectory(atPath: appCacheDirectory as String,
+ withIntermediateDirectories: false, attributes: nil)
+ } catch let error {
NSLog("Aerial Error: Couldn't create cache directory: \(error)")
return nil
}
@@ -64,7 +63,6 @@ class VideoCache {
NSLog("Aerial Error: Couldn't get video cache path!")
return false
}
-
let fileManager = FileManager.default
@@ -167,8 +165,7 @@ class VideoCache {
do {
try mutableVideoData.write(toFile: videoCachePath, options: .atomicWrite)
- }
- catch let error {
+ } catch let error {
NSLog("Aerial Error: Couldn't write cache file: \(error)")
}
}
@@ -236,7 +233,7 @@ class VideoCache {
// Whether the video cache can fulfill this request
func canFulfillLoadingRequest(_ loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
- if (loading == false) {
+ if !loading {
return true
}
@@ -261,7 +258,6 @@ class VideoCache {
return false
}
-
// MARK: - Consolidating
func consolidateLoadedRanges() {
@@ -289,8 +285,7 @@ class VideoCache {
consolidatedRanges.remove(at: lastIndex!)
consolidatedRanges.append(previousRange!)
continue
- }
- else {
+ } else {
// skip adding this to the array, previous range is already bigger
// debugLog("skipping add of \(range), previous: \(previousRange)")
continue
@@ -8,11 +8,12 @@
import Foundation
-
-protocol VideoDownloadDelegate : NSObjectProtocol {
- func videoDownload(_ videoDownload: VideoDownload , finished success: Bool, errorMessage: String?)
+protocol VideoDownloadDelegate: NSObjectProtocol {
+ func videoDownload(_ videoDownload: VideoDownload,
+ finished success: Bool, errorMessage: String?)
// bytes received for bytes/second count
- func videoDownload(_ videoDownload: VideoDownload, receivedBytes: Int, progress: Float)
+ func videoDownload(_ videoDownload: VideoDownload,
+ receivedBytes: Int, progress: Float)
}
class VideoDownloadStream {
@@ -29,7 +30,7 @@ class VideoDownloadStream {
}
}
-class VideoDownload : NSObject, NSURLConnectionDataDelegate {
+class VideoDownload: NSObject, NSURLConnectionDataDelegate {
var streams: [VideoDownloadStream] = []
weak var delegate: VideoDownloadDelegate!
@@ -67,8 +68,8 @@ class VideoDownload : NSObject, NSURLConnectionDataDelegate {
debugLog("Starting download for range \(requestRangeField)")
}
-
- guard let connection = NSURLConnection(request: request as URLRequest, delegate: self, startImmediately: false) else {
+ guard let connection = NSURLConnection(request: request as URLRequest,
+ delegate: self, startImmediately: false) else {
NSLog("Aerial: Error creating connection with request: \(request)")
return
}
@@ -115,14 +116,13 @@ class VideoDownload : NSObject, NSURLConnectionDataDelegate {
// let queue = DispatchQueue.main
for i in 0 ..< streamCount {
let isLastStream: Bool = i == (streamCount - 1)
- var range: NSRange = NSMakeRange(offset, streamPiece)
+ var range = NSRange(location: offset, length: streamPiece)
if isLastStream {
let bytesLeft = contentLength - offset
- range = NSMakeRange(offset, bytesLeft)
+ range = NSRange(location: offset, length: bytesLeft)
debugLog("last stream range: \(range)")
}
-
let delay = DispatchTime.now() + Double(Int64(delayTime * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
queue.asyncAfter(deadline: delay) {
@@ -144,7 +144,8 @@ class VideoDownload : NSObject, NSURLConnectionDataDelegate {
return
}
- let replaceRange = NSMakeRange(stream.downloadOffset, receivedData.count)
+ let replaceRange = NSRange(location: stream.downloadOffset,
+ length: receivedData.count)
videoData.replaceBytes(in: replaceRange, withBytes: (receivedData as NSData).bytes)
stream.downloadOffset += receivedData.count
}
@@ -165,8 +166,7 @@ class VideoDownload : NSObject, NSURLConnectionDataDelegate {
var errorMessage: String?
do {
try videoData.write(toFile: videoCachePath, options: .atomicWrite)
- }
- catch let error {
+ } catch let error {
NSLog("Aerial Error: Couldn't write cache file: \(error)")
errorMessage = "Couldn't write to cache file!"
success = false
@@ -201,8 +201,7 @@ class VideoDownload : NSObject, NSURLConnectionDataDelegate {
})
return
- }
- else {
+ } else {
// get real offset of receiving data
queue.async(execute: { () -> Void in
@@ -275,10 +274,11 @@ class VideoDownload : NSObject, NSURLConnectionDataDelegate {
// MARK: - Range
func startOffsetFromResponse(_ response: URLResponse) -> Int? {
// get range response
- var regex : NSRegularExpression!
+ var regex: NSRegularExpression!
do {
// Check to see if the server returned a valid byte-range
- regex = try NSRegularExpression(pattern: "bytes (\\d+)-\\d+/\\d+", options: NSRegularExpression.Options.caseInsensitive)
+ regex = try NSRegularExpression(pattern: "bytes (\\d+)-\\d+/\\d+",
+ options: NSRegularExpression.Options.caseInsensitive)
} catch let error as NSError {
NSLog("Aerial: Error formatting regex: \(error)")
return nil
@@ -291,7 +291,9 @@ class VideoDownload : NSObject, NSURLConnectionDataDelegate {
return nil
}
- guard let match : NSTextCheckingResult = regex.firstMatch(in: contentRange as String, options: NSRegularExpression.MatchingOptions.anchored, range: NSMakeRange(0, contentRange.length)) else {
+ guard let match = regex.firstMatch(in: contentRange as String,
+ options: NSRegularExpression.MatchingOptions.anchored,
+ range: NSRange(location:0, length: contentRange.length)) else {
debugLog("Weird, couldn't make a regex match for byte offset: \(contentRange)")
return nil
}
Oops, something went wrong.

0 comments on commit ad50032

Please sign in to comment.