Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

@orta: Swift 2 #496

Merged
merged 9 commits into from
Aug 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Kiosk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@
5EB0B6E51A5C3E6800B7CBF2 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = Artsy;
TargetAttributes = {
Expand Down
4 changes: 2 additions & 2 deletions Kiosk/Admin/AdminLogViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AdminLogViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
textView.text = NSString(contentsOfURL: logPath(), encoding: NSASCIIStringEncoding, error: nil) as! String
textView.text = try? NSString(contentsOfURL: logPath(), encoding: NSASCIIStringEncoding) as String
}

@IBOutlet weak var textView: UITextView!
Expand All @@ -13,7 +13,7 @@ class AdminLogViewController: UIViewController {
}

func logPath() -> NSURL {
let docs = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).last as! NSURL
let docs = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).last!
return docs.URLByAppendingPathComponent("logger.txt")
}

Expand Down
3 changes: 1 addition & 2 deletions Kiosk/Admin/AuctionWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ class AuctionWebViewController: WebViewController {
override func viewDidLoad() {
super.viewDidLoad()

let toolbarButtons = self.toolbarItems
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: "")

let exitImage = UIImage(named: "toolbar_close")
let backwardBarItem = UIBarButtonItem(image: exitImage, style: .Plain, target: self, action: "exit");
let allItems = self.toolbarItems! + [flexibleSpace, backwardBarItem] as [AnyObject]
let allItems = self.toolbarItems! + [flexibleSpace, backwardBarItem]
toolbarItems = allItems
}

Expand Down
2 changes: 1 addition & 1 deletion Kiosk/Admin/ChooseAuctionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ChooseAuctionViewController: UIViewController {
.subscribeNext({ [weak self] (activeSales) -> Void in
self!.auctions = activeSales as! [Sale]

for i in 0 ..< count(self!.auctions) {
for i in 0 ..< self!.auctions.count {
let sale = self!.auctions[i]
let title = " \(sale.name) - #\(sale.auctionState) - \(sale.artworkCount)"

Expand Down
6 changes: 3 additions & 3 deletions Kiosk/App/AppDelegate+GlobalActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public extension AppDelegate {
RACObserve(self, "helpViewController").notNil().subscribeNext {
let isVisible = $0 as! Bool

var image: UIImage? = isVisible ? UIImage(named: "xbtn_white")?.imageWithRenderingMode(.AlwaysOriginal) : nil
var text: String? = isVisible ? nil : "HELP"
let image: UIImage? = isVisible ? UIImage(named: "xbtn_white")?.imageWithRenderingMode(.AlwaysOriginal) : nil
let text: String? = isVisible ? nil : "HELP"

self.helpButton.setTitle(text, forState: .Normal)
self.helpButton.setImage(image, forState: .Normal)
Expand Down Expand Up @@ -238,7 +238,7 @@ private extension AppDelegate {
// MARK: - Computed property signals

var fullfilmentVisibleSignal: RACSignal {
return RACSignal.defer {
return RACSignal.`defer` {
return RACSignal.createSignal { (subscriber) -> RACDisposable! in
subscriber.sendNext((self.appViewController.presentedViewController as? FulfillmentContainerViewController) != nil)
subscriber.sendCompleted()
Expand Down
6 changes: 3 additions & 3 deletions Kiosk/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
}

// I couldn't figure how to swizzle this out like we do in objc.
if let inTests: AnyClass = NSClassFromString("XCTest") { return true }
if let _ = NSClassFromString("XCTest") { return true }

// Clear possible old contents from cache and defaults.
let imageCache = SDImageCache.sharedImageCache()
Expand All @@ -37,7 +37,7 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
defaults.removeObjectForKey(XAppToken.DefaultsKeys.TokenExpiry.rawValue)

let auctionStoryboard = UIStoryboard.auction()
window?.rootViewController = auctionStoryboard.instantiateInitialViewController() as? UIViewController
window?.rootViewController = auctionStoryboard.instantiateInitialViewController()
window?.makeKeyAndVisible()

let keys = EidolonKeys()
Expand Down Expand Up @@ -69,7 +69,7 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
let agentString = "\(oldAgent) Artsy-Mobile/\(version!) Eigen/\(build!) Kiosk Eidolon"

let defaults = NSUserDefaults.standardUserDefaults()
let userAgentDict = ["UserAgent" as NSObject : agentString]
let userAgentDict = ["UserAgent": agentString]
defaults.registerDefaults(userAgentDict)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Kiosk/App/AppSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit

class AppSetup {

lazy var auctionID = "los-angeles-modern-auctions-march-2015"
var auctionID = "los-angeles-modern-auctions-march-2015"
lazy var useStaging = true
lazy var showDebugButtons = false
lazy var disableCardReader = false
Expand All @@ -25,6 +25,6 @@ class AppSetup {
showDebugButtons = defaults.boolForKey("KioskShowDebugButtons")
disableCardReader = defaults.boolForKey("KioskDisableCardReader")

if let inTests: AnyClass = NSClassFromString("XCTest") { isTesting = true }
if let _ = NSClassFromString("XCTest") { isTesting = true }
}
}
2 changes: 1 addition & 1 deletion Kiosk/App/AppViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension AppViewController {
func auctionRequestSignal(auctionID: String) -> RACSignal {
let auctionEndpoint: ArtsyAPI = ArtsyAPI.AuctionInfo(auctionID: auctionID)

return XAppRequest(auctionEndpoint).filterSuccessfulStatusCodes().mapJSON().mapToObject(Sale.self).catch({ (error) -> RACSignal! in
return XAppRequest(auctionEndpoint).filterSuccessfulStatusCodes().mapJSON().mapToObject(Sale.self).`catch`({ (error) -> RACSignal! in

logger.log("Sale Artworks: Error handling thing: \(error.artsyServerError())")
return RACSignal.empty()
Expand Down
8 changes: 4 additions & 4 deletions Kiosk/App/BidderDetailsRetrieval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public extension UIViewController {

extension UIAlertController {
class func successfulBidderDetailsAlertController() -> UIAlertController {
let alertController = self(title: "Your details have been sent", message: nil, preferredStyle: .Alert)
let alertController = self.init(title: "Your details have been sent", message: nil, preferredStyle: .Alert)
alertController.addAction(RACAlertAction(title: "OK", style: .Default))

return alertController
}

class func failedBidderDetailsAlertController() -> UIAlertController {
let alertController = self(title: "Incorrect Email", message: "Email was not recognized. You may not be registered to bid yet.", preferredStyle: .Alert)
let alertController = self.init(title: "Incorrect Email", message: "Email was not recognized. You may not be registered to bid yet.", preferredStyle: .Alert)
alertController.addAction(RACAlertAction(title: "Cancel", style: .Cancel))

let retryAction = RACAlertAction(title: "Retry", style: .Default)
Expand All @@ -55,13 +55,13 @@ extension UIAlertController {
}

class func emailPromptAlertController() -> (UIAlertController, RACCommand) {
let alertController = self(title: "Send Bidder Details", message: "Enter your email address registered with Artsy and we will send your bidder number and PIN.", preferredStyle: .Alert)
let alertController = self.init(title: "Send Bidder Details", message: "Enter your email address registered with Artsy and we will send your bidder number and PIN.", preferredStyle: .Alert)

let ok = RACAlertAction(title: "OK", style: .Default)
ok.command = RACCommand { (_) -> RACSignal! in

return RACSignal.createSignal { (subscriber) -> RACDisposable! in
let text = (alertController.textFields?.first as? UITextField)?.text ?? ""
let text = (alertController.textFields?.first)?.text ?? ""
subscriber.sendNext(text)
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions Kiosk/App/CardHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class CardHandler: NSObject, CFTReaderDelegate {
})

} else if let error = error {
self.cardSwipedSignal.sendNext("response Error");
self.cardSwipedSignal.sendNext("response Error \(error)");
logger.log("CardReader got a response it cannot handle")


Expand Down Expand Up @@ -105,10 +105,10 @@ public class LocalCardReader: CFTReader {
override public func beginSwipeWithMessage(message: String!) {
if fail {
let error = NSError(domain: "eidolon", code: 111, userInfo: nil)
self.delegate.readerCardResponse(nil, withError: error)
self.delegate?.readerCardResponse(nil, withError: error)

} else {
self.delegate.readerCardResponse(CFTCard(), withError: nil)
self.delegate?.readerCardResponse(CFTCard(), withError: nil)
}
}
}
2 changes: 1 addition & 1 deletion Kiosk/App/GlobalFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func delayToMainThread(delay:Double, closure:()->()) {
}

func logPath() -> NSURL {
let docs = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).last as! NSURL
let docs = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).last!
return docs.URLByAppendingPathComponent("logger.txt")
}

Expand Down
20 changes: 10 additions & 10 deletions Kiosk/App/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ public class Logger {
if let path = self.destination.path {
NSFileManager.defaultManager().createFileAtPath(path, contents: nil, attributes: nil)
var error: NSError?
let fileHandle = NSFileHandle(forWritingToURL: self.destination, error: &error)

if fileHandle == nil {
println("Serious error in logging: could not open path to log file. \(error).")
if let fileHandle = try? NSFileHandle(forWritingToURL: self.destination) {
print("Successfully logging to: \(path)")
return fileHandle
} else {
println("Successfully logging to: \(path)")
print("Serious error in logging: could not open path to log file. \(error).")
}

return fileHandle
} else {
println("Serious error in logging: specified destination (\(self.destination)) does not appear to have a path component.")
return nil
print("Serious error in logging: specified destination (\(self.destination)) does not appear to have a path component.")
}

return nil
}()

public init(destination: NSURL) {
Expand All @@ -48,7 +47,8 @@ private extension Logger {
func stringRepresentation(message: String, function: String, file: String, line: Int) -> String {
let dateString = dateFormatter.stringFromDate(NSDate())

return "\(dateString) [\(file.lastPathComponent):\(line)] \(function): \(message)\n"
let file = NSURL(fileURLWithPath: file).lastPathComponent ?? "(Unknown File)"
return "\(dateString) [\(file):\(line)] \(function): \(message)\n"
}

func printToConsole(logMessage: String) {
Expand All @@ -59,7 +59,7 @@ private extension Logger {
if let data = logMessage.dataUsingEncoding(NSUTF8StringEncoding) {
fileHandle?.writeData(data)
} else {
println("Serious error in logging: could not encode logged string into data.")
print("Serious error in logging: could not encode logged string into data.")
}
}
}
10 changes: 5 additions & 5 deletions Kiosk/App/Models/Artwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class Artwork: JSONAble {
let price = json["price"].stringValue
let date = json["date"].stringValue
let sold = json["sold"].stringValue
let titleAndDate = titleAndDateAttributedString(title, dateString)
let titleAndDate = titleAndDateAttributedString(title, dateString: dateString)

let artwork = Artwork(id: id, dateString: dateString, title: title, titleAndDate:titleAndDate, price: price, date: date, sold: sold)

Expand All @@ -81,7 +81,7 @@ public class Artwork: JSONAble {
// There's a possibility that image_versions comes back as null from the API, which fromJSON() is allergic to.
artwork.images = imageDicts.filter { dict -> Bool in
let imageVersions = (dict["image_versions"] as? [String]) ?? []
return count(imageVersions) > 0
return imageVersions.count > 0
}.map { return Image.fromJSON($0) as! Image }
}

Expand Down Expand Up @@ -109,11 +109,11 @@ public class Artwork: JSONAble {
}

private func titleAndDateAttributedString(title: String, dateString: String) -> NSAttributedString {
let workTitle = count(title) > 0 ? title : "Untitled"
let workTitle = title.isEmpty ? "Untitled" : title
let workFont = UIFont.serifItalicFontWithSize(16)
var attributedString = NSMutableAttributedString(string: workTitle, attributes: [NSFontAttributeName : workFont ])
let attributedString = NSMutableAttributedString(string: workTitle, attributes: [NSFontAttributeName : workFont ])

if count(dateString) > 0 {
if dateString.isNotEmpty {
let dateFont = UIFont.serifFontWithSize(16)
let dateString = NSMutableAttributedString(string: ", " + dateString, attributes: [ NSFontAttributeName : dateFont ])
attributedString.appendAttributedString(dateString)
Expand Down
12 changes: 1 addition & 11 deletions Kiosk/App/Models/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,11 @@ public class Image: JSONAble {
return urlFromPreferenceList(["larger", "large", "medium"])
}

public func localImageTileForLevel(level:Int, x:Int, y:Int) -> UIImage? {
let path = localPathForImageTileAtLevel(level, x:x, y:y)
return UIImage(contentsOfFile:path as String)
}

private func urlFromPreferenceList(preferenceList: Array<String>) -> NSURL? {
if let format = preferenceList.filter({ contains(self.imageVersions, $0) }).first {
if let format = preferenceList.filter({ self.imageVersions.contains($0) }).first {
let path = NSString(string: self.imageFormatString).stringByReplacingOccurrencesOfString(":version", withString: format)
return NSURL(string: path)
}
return nil
}

func localPathForImageTileAtLevel(level:Int, x:Int, y:Int) -> NSString {
let directoryURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as! NSURL
return ""
}
}
2 changes: 1 addition & 1 deletion Kiosk/App/Models/JSONAble.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public class JSONAble: NSObject {
public class func fromJSON([String:AnyObject]) -> JSONAble {
public class func fromJSON(_: [String:AnyObject]) -> JSONAble {
return JSONAble()
}
}
4 changes: 2 additions & 2 deletions Kiosk/App/Models/SaleArtwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public class SaleArtwork: JSONAble {
}
}

public func currentBidSignal(prefix: String = "", missingPrefix: String = "") -> RACSignal {
public func currentBidSignal(prefix prefix: String = "", missingPrefix: String = "") -> RACSignal {
return RACObserve(self, "highestBidCents").map({ [weak self] (highestBidCents) -> AnyObject! in
if let currentBidCents = highestBidCents as? Int {
return "\(prefix)\(NSNumberFormatter.currencyStringForCents(currentBidCents))"
Expand All @@ -180,7 +180,7 @@ public class SaleArtwork: JSONAble {
})
}

override public class func keyPathsForValuesAffectingValueForKey(key: String) -> Set<NSObject> {
override public class func keyPathsForValuesAffectingValueForKey(key: String) -> Set<String> {
if key == "estimateString" {
return ["lowEstimateCents", "highEstimateCents"] as Set
} else if key == "lotNumberSignal" {
Expand Down
1 change: 0 additions & 1 deletion Kiosk/App/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class User: JSONAble {
let email = json["email"].stringValue
let paddleNumber = json["paddle_number"].stringValue
let phoneNumber = json["phone"].stringValue
let postalCode = json["location"]["postal_code"].stringValue

var location:Location?
if let bidDictionary = json["location"].object as? [String: AnyObject] {
Expand Down
4 changes: 2 additions & 2 deletions Kiosk/App/NSErrorExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import Moya
extension NSError {

func artsyServerError() -> NSString {
if let errorJSON = userInfo?["data"] as? [String: AnyObject] {
if let errorJSON = userInfo["data"] as? [String: AnyObject] {
let error = GenericError.fromJSON(errorJSON) as! GenericError
return "\(error.message) - \(error.detail) + \(error.detail)"
} else if let response = userInfo?["data"] as? MoyaResponse {
} else if let response = userInfo["data"] as? MoyaResponse {
let stringData = NSString(data: response.data, encoding: NSUTF8StringEncoding)
return "Status Code: \(response.statusCode), Data Length: \(response.data.length), String Data: \(stringData)"
}
Expand Down
2 changes: 1 addition & 1 deletion Kiosk/App/Networking/APIKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct APIKeys {
// MARK: Methods

public var stubResponses: Bool {
return count(key) < minimumKeyLength || count(secret) < minimumKeyLength
return key.characters.count < minimumKeyLength || secret.characters.count < minimumKeyLength
}

// MARK: Initializers
Expand Down
Loading