Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate source to Swift 3, bump to 2.0.0 #23

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions tvOS-App/CCC-TV/CCC-TV/AppDelegate.swift
Expand Up @@ -10,8 +10,8 @@ import UIKit
import CoreData
import TVMLKit

let build = NSBundle.mainBundle().infoDictionary?.indexForKey(kCFBundleVersionKey as String)
let version = (NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"]?.description)! as String
let build = Bundle.main.infoDictionary?.index(forKey: kCFBundleVersionKey as String)
let version = (Bundle.main.infoDictionary?["CFBundleShortVersionString"]?.description)! as String

var globalJsContext: JSContext?

Expand All @@ -28,8 +28,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDe
//static let TVBaseURL = "http://localhost:9001"
static var TVBaseURL: String {
get {
let version = (NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"]?.description)! as String
let environment: Dictionary = NSProcessInfo.processInfo().environment
let version = (Bundle.mainBundle().infoDictionary?["CFBundleShortVersionString"]?.description)! as String
let environment: Dictionary = ProcessInfo.processInfo().environment
if let serverenvironment = environment["server-environment"] {
NSLog("Server environment \(serverenvironment).")
switch serverenvironment {
Expand All @@ -54,7 +54,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDe

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window = UIWindow(frame: UIScreen.main.bounds)
print("Build: \(build) Versin: \(version)")
print("URL: \(AppDelegate.TVBaseURL)")

Expand All @@ -74,7 +74,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDe
the user quickly.
*/
if let javaScriptURL = NSURL(string: AppDelegate.TVBootURL) {
appControllerContext.javaScriptApplicationURL = javaScriptURL
appControllerContext.javaScriptApplicationURL = javaScriptURL as URL
}

appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL
Expand Down Expand Up @@ -102,7 +102,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDe
}

func appController(appController: TVApplicationController, didFailWithError error: NSError) {
print("\(__FUNCTION__) invoked with error: \(error)")
print("\(#function) invoked with error: \(error)")

let title = "Error Launching Application"
let message = error.localizedDescription
Expand Down
16 changes: 8 additions & 8 deletions tvOS-App/CCC-TV/CCC-TV/Exports/ConferencesExport.swift
Expand Up @@ -26,7 +26,7 @@ class ConferencesExport: NSObject, ConferencesExportProtocol {
("title", conference.title)
, ("acronym", conference.acronym)
, ("logo_url", conference.logo_url.absoluteString)
, ("updated_at", NSDateFormatter.localizedStringFromDate(conference.updated_at, dateStyle: .MediumStyle, timeStyle: .MediumStyle) )
, ("updated_at", DateFormatter.localizedStringFromDate(conference.updated_at as Date, dateStyle: .mediumStyle, timeStyle: .mediumStyle) )
, ("aspect_ratio", conference.aspect_ratio)
, ("schedule_url", conference.schedule_url.absoluteString)
, ("images_url", conference.images_url.absoluteString)
Expand Down Expand Up @@ -56,9 +56,9 @@ class ConferencesExport: NSObject, ConferencesExportProtocol {
, ("url", event.url.absoluteString)
, ("link", (event.link?.absoluteString) ?? "")
, ("frontend_link", (event.frontend_link?.absoluteString) ?? "")
, ("date", NSDateFormatter.localizedStringFromDate(event.date ?? NSDate(), dateStyle: .MediumStyle, timeStyle: .MediumStyle) )
, ("release_date", NSDateFormatter.localizedStringFromDate(event.release_date ?? NSDate(), dateStyle: .MediumStyle, timeStyle: .MediumStyle) )
, ("updated_at", NSDateFormatter.localizedStringFromDate(event.updated_at!, dateStyle: .MediumStyle, timeStyle: .MediumStyle) )
, ("date", DateFormatter.localizedStringFromDate(event.date ?? NSDate(), dateStyle: .MediumStyle, timeStyle: .MediumStyle) )
, ("release_date", DateFormatter.localizedStringFromDate(event.release_date ?? NSDate(), dateStyle: .MediumStyle, timeStyle: .MediumStyle) )
, ("updated_at", DateFormatter.localizedStringFromDate(event.updated_at!, dateStyle: .MediumStyle, timeStyle: .MediumStyle) )
, ("poster_url", (event.poster_url?.absoluteString) ?? "")
, ("thumb_url", (event.thumb_url?.absoluteString) ?? "")
, ("conference_url", (event.conference_url?.absoluteString) ?? "")
Expand All @@ -77,19 +77,19 @@ class ConferencesExport: NSObject, ConferencesExportProtocol {
downloader.performDownload(){
globalJsContext?.evaluateScript("updateUI();")
let conferences = self.conferenceStructToObject()
fn.callWithArguments(conferences)
fn.call(withArguments: conferences)
}
return Array(arrayLiteral: Dictionary())
}
}

func eventsOfConference(id: NSString, fn: JSValue){
func eventsOfConference(url id: NSString, fn: JSValue){
if(allEvents.count > 0){
print("# events from the cahce")
let events = self.eventStructToObject(withEventId: Int(id as String)!)

NSLog("events length \(events.count)");
fn.callWithArguments(events)
fn.call(withArguments: events)

} else {
let eventsDownloader = DownloadEventsOperation(eventId: Int(id as String)!)
Expand All @@ -111,4 +111,4 @@ class ConferencesExport: NSObject, ConferencesExportProtocol {
}
}



2 changes: 1 addition & 1 deletion tvOS-App/CCC-TV/CCC-TV/Info.plist
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<string>2.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Expand Up @@ -9,7 +9,7 @@
import Foundation
import SwiftyJSON

class DownloadConferencesOperation: NSOperation {
class DownloadConferencesOperation: Operation {

private var _finished: Bool = false {
willSet {
Expand All @@ -19,13 +19,13 @@ class DownloadConferencesOperation: NSOperation {
self.didChangeValueForKey("isFinished");
}
}
override var finished: Bool {
override var isFinished: Bool {
get {
return _finished
}
}

let dateFormatter = NSDateFormatter()
let dateFormatter = DateFormatter()

override init(){
dateFormatter.dateFormat = "yyyy-MM-dd'T'kk:mm:ss.SSSxxxxx"
Expand All @@ -47,7 +47,7 @@ class DownloadConferencesOperation: NSOperation {
title: subJson["title"].stringValue
, acronym: subJson["acronym"].stringValue
, logo_url: NSURL(string: subJson["logo_url"].stringValue)!
, updated_at: self.dateFormatter.dateFromString(subJson["updated_at"].stringValue)!
, updated_at: self.dateFormatter.dateFromString(subJson["updated_at"].stringValue)! as NSDate
, aspect_ratio: subJson["aspect_ratio"].stringValue
, schedule_url: NSURL(string: subJson["schedule_url"].stringValue)!
, images_url: NSURL(string: subJson["images_url"].stringValue)!
Expand All @@ -59,7 +59,7 @@ class DownloadConferencesOperation: NSOperation {
allConferences.append(conference)
}
}
allConferences.sortInPlace({ $0.updated_at.compare($1.updated_at) == NSComparisonResult.OrderedDescending })
allConferences.sortInPlace({ $0.updated_at.compare($1.updated_at) == ComparisonResultrderedDescending })

self._finished = true
}
Expand Down
Expand Up @@ -9,25 +9,25 @@
import Foundation
import SwiftyJSON

class DownloadEventsOperation: NSOperation {
class DownloadEventsOperation: Operation {

private let eventId: Int

private var _finished: Bool = false {
willSet {
self.willChangeValueForKey("isFinished");
self.willChangeValue(forKey: "isFinished");
}
didSet {
self.didChangeValueForKey("isFinished");
self.didChangeValue(forKey: "isFinished");
}
}
override var finished: Bool {
override var isFinished: Bool {
get {
return _finished
}
}

let dateFormatter = NSDateFormatter()
let dateFormatter = DateFormatter()

init(eventId: Int){
dateFormatter.dateFormat = "yyyy-MM-dd'T'kk:mm:ss.SSSxxxxx"
Expand All @@ -49,7 +49,7 @@ class DownloadEventsOperation: NSOperation {
}
allEvents[self.eventId] = allEvents[self.eventId]!.filter({$0.guid != guid})
var defaultDate = "1970-01-01T00:00:00.000+00:00"
if(subJson["date"].isExists() && subJson["date"].stringValue != ""){
if(subJson["date"].exists() && subJson["date"].stringValue != "") {
defaultDate = subJson["date"].stringValue
}
var event = Event(
Expand All @@ -65,24 +65,24 @@ class DownloadEventsOperation: NSOperation {
, url: NSURL(string: subJson["url"].stringValue)!
, link: NSURL(string: subJson["link"].stringValue)
, frontend_link: NSURL(string: subJson["frontend_link"].stringValue)
, date: self.dateFormatter.dateFromString(defaultDate)!
, date: self.dateFormatter.date(from: defaultDate)! as NSDate
, release_date: nil
, updated_at: self.dateFormatter.dateFromString(subJson["updated_at"].stringValue)
, updated_at: self.dateFormatter.date(from: subJson["updated_at"].stringValue) as NSDate?
, poster_url: NSURL(string: subJson["poster_url"].stringValue)
, thumb_url: NSURL(string: subJson["thumb_url"].stringValue)
, conference_url: NSURL(string: subJson["conference_url"].stringValue)
)

if subJson["release_date"].isExists() {
event.release_date = self.dateFormatter.dateFromString(subJson["release_date"].stringValue)
if subJson["release_date"].exists() {
event.release_date = self.dateFormatter.date(from: subJson["release_date"].stringValue) as NSDate?
} else {
event.release_date = NSDate()
}
allEvents[self.eventId]!.append(event)
}
}
if(allEvents.keys.contains(self.eventId)){
allEvents[self.eventId]!.sortInPlace({ $0.date.compare($1.date) == NSComparisonResult.OrderedDescending })
if(allEvents.keys.contains(self.eventId)) {
allEvents[self.eventId]!.sort(by: { $0.date.compare($1.date as Date) == ComparisonResult.orderedDescending })
}
self._finished = true
}
Expand Down
4 changes: 2 additions & 2 deletions tvOS-App/CCC-TV/CCC-TV/NetworkOperations/Downloader.swift
Expand Up @@ -8,7 +8,7 @@

import Foundation

var downloadQueue = NSOperationQueue()
var downloadQueue = OperationQueue()

class Downloader {

Expand All @@ -26,4 +26,4 @@ class Downloader {
downloadQueue.addOperation(conferencesDownloader)
}

}
}
Expand Up @@ -23,10 +23,10 @@ class ConferencesRequest: Requestable {
if self._json != nil {
return _json!
}
return JSON(data: "{}".dataUsingEncoding(NSUTF8StringEncoding)!)
return JSON(data: "{}".data(using: String.Encoding.utf8)!)
}
set(newJson) {
self._json = newJson
}
}
}
}
Expand Up @@ -30,7 +30,7 @@ class EventsRequest: Requestable {
if self._json != nil {
return _json!
}
return JSON(data: "{}".dataUsingEncoding(NSUTF8StringEncoding)!)
return JSON(data: "{}".data(usingEncoding: NSUTF8StringEncoding)!)
}
set(newJson) {
self._json = newJson
Expand Down
20 changes: 10 additions & 10 deletions tvOS-App/CCC-TV/CCC-TV/Requestable.swift
Expand Up @@ -27,21 +27,21 @@ protocol Requestable {

extension Requestable {

mutating func performRequest(completionHandler: (RequestError?, JSON?)->()) {
mutating func performRequest(completionHandler: @escaping (RequestError?, JSON?)->()) {
let url = NSURL(string: "\(apiUrl)\(requestUrl)")

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let configuration = URLSessionConfiguration.default

let request = NSURLRequest(URL: url!)
let request = URLRequest(url: url! as URL)

let session = NSURLSession(
let session = URLSession(
configuration: configuration
, delegate: SessionDelegate()
, delegateQueue: NSOperationQueue.mainQueue()
, delegateQueue: OperationQueue.main
)

let task = session.dataTaskWithRequest(request){
(data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
let task = session.dataTask(with: request) {
(data: NSData?, response: URLResponse?, error: NSError?) -> Void in

if error != nil {
NSLog(error!.localizedDescription)
Expand All @@ -62,9 +62,9 @@ extension Requestable {

}

class SessionDelegate: NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate {
class SessionDelegate: NSObject, URLSessionDelegate, URLSessionTaskDelegate {

func URLSession(session: NSURLSession, task: NSURLSessionTask, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
func URLSession(session: URLSession, task: NSURLSessionTask, didReceiveChallenge challenge: URLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
if let trust = challenge.protectionSpace.serverTrust {
completionHandler(
NSURLSessionAuthChallengeDisposition.UseCredential
Expand All @@ -75,7 +75,7 @@ class SessionDelegate: NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate
}
}

func URLSession(session: NSURLSession, task: NSURLSessionTask, willPerformHTTPRedirection response: NSHTTPURLResponse, newRequest request: NSURLRequest, completionHandler: (NSURLRequest?) -> Void) {
func URLSession(session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: NSHTTPURLResponse, newRequest request: NSURLRequest, completionHandler: (NSURLRequest?) -> Void) {
let newRequest : NSURLRequest? = request
completionHandler(newRequest)
}
Expand Down