Skip to content

Commit

Permalink
Fixes for Xcode 6 Beta 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Sep 2, 2014
1 parent 479165f commit e30d97c
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 65 deletions.
10 changes: 5 additions & 5 deletions SwiftHN/Activities/OpenSafariActivity.swift
Expand Up @@ -9,23 +9,23 @@
import UIKit

class OpenSafariActivity: UIActivity {
override func activityType() -> String! {
override func activityType() -> String {
return "Open in Safari"
}

override func activityTitle() -> String! {
override func activityTitle() -> String {
return "Open in Safari"
}

override func activityImage() -> UIImage! {
override func activityImage() -> UIImage {
return UIImage(named: "Safari-White")
}

override func canPerformWithActivityItems(activityItems: [AnyObject]!) -> Bool {
override func canPerformWithActivityItems(activityItems: [AnyObject]) -> Bool {
return true
}

override func prepareWithActivityItems(activityItems: [AnyObject]!) {
override func prepareWithActivityItems(activityItems: [AnyObject]) {
var urlToOpen = activityItems[1] as NSURL
UIApplication.sharedApplication().openURL(urlToOpen)
}
Expand Down
6 changes: 3 additions & 3 deletions SwiftHN/Cells/CommentsCell.swift
Expand Up @@ -61,7 +61,7 @@ class CommentsCell: UITableViewCell {
super.init(coder: aDecoder)
}

override init(style: UITableViewCellStyle, reuseIdentifier: String) {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
self.indentation = CommentCellMarginConstant
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
Expand All @@ -84,8 +84,8 @@ class CommentsCell: UITableViewCell {
self.commentLabel.textContainerInset = UIEdgeInsetsZero
self.commentLabel.contentInset = UIEdgeInsetsZero

self.commentLabel.frame.size.width = self.contentView.bounds.width - (self.commentLeftMarginConstraint.constant * 2) - (CommentCellMarginConstant * CGFloat(self.comment.depth!))
self.indentation = CommentCellMarginConstant + (CommentCellMarginConstant * CGFloat(self.comment.depth!))
self.commentLabel.frame.size.width = self.contentView.bounds.width - (self.commentLeftMarginConstraint.constant * 2) - (CommentCellMarginConstant * CGFloat(self.comment.depth))
self.indentation = CommentCellMarginConstant + (CommentCellMarginConstant * CGFloat(self.comment.depth))
}

class func heightForText(text: String, bounds: CGRect, level: Int) -> CGFloat {
Expand Down
8 changes: 2 additions & 6 deletions SwiftHN/Cells/NewsCell.swift
Expand Up @@ -41,12 +41,8 @@ class NewsCell: UITableViewCell {
didSet{
self.titleLabel.text = self.post.title!
self.urlLabel.text = self.post.domain! + " - " + self.post.prettyTime!
if let points: Int = self.post.points {
self.voteLabel.labelText = String(points) + " votes"
}
if let count: Int = self.post.commentsCount {
self.commentsLabel.labelText = String(count) + " comments"
}
self.voteLabel.labelText = String(self.post.points) + " votes"
self.commentsLabel.labelText = String(self.post.commentsCount) + " comments"
self.usernameLabel.labelText = self.post.username!

self.voteLabel.onButtonTouch = {(sender: UIButton) in
Expand Down
4 changes: 2 additions & 2 deletions SwiftHN/Utils/Helpers.swift
Expand Up @@ -27,9 +27,9 @@ class Helper {
var sheet = UIActivityViewController(activityItems: [NSString(string: post.title!), post.url!], applicationActivities: [OpenSafariActivity()])
if sheet.popoverPresentationController != nil {
sheet.modalPresentationStyle = UIModalPresentationStyle.Popover
sheet.popoverPresentationController.sourceView = controller.view
sheet.popoverPresentationController?.sourceView = controller.view
if let barbutton = barbutton {
sheet.popoverPresentationController.barButtonItem = barbutton
sheet.popoverPresentationController?.barButtonItem = barbutton
}
}
controller.presentViewController(sheet, animated: true, completion: nil)
Expand Down
12 changes: 6 additions & 6 deletions SwiftHN/ViewControllers/CategoriesViewController.swift
Expand Up @@ -42,21 +42,21 @@ class CategoriesViewController: UITableViewController {
// Dispose of any resources that can be recreated.
}

override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath)
if (cell.textLabel.text == "Hacker News") {
if (cell?.textLabel?.text == "Hacker News") {
self.delegate?.categoriesViewControllerDidSelecteFilter(self, filer: .Top, title: "HN:News")
}
else if (cell.textLabel.text == "Latest") {
else if (cell?.textLabel?.text == "Latest") {
self.delegate?.categoriesViewControllerDidSelecteFilter(self, filer: .New, title: "HN:Latest")
}
else if (cell.textLabel.text == "Jobs") {
else if (cell?.textLabel?.text == "Jobs") {
self.delegate?.categoriesViewControllerDidSelecteFilter(self, filer: .Jobs, title: "HN:Jobs")
}
else if (cell.textLabel.text == "Ask HN") {
else if (cell?.textLabel?.text == "Ask HN") {
self.delegate?.categoriesViewControllerDidSelecteFilter(self, filer: .Ask, title: "HN:Ask")
}
else if (cell.textLabel.text == "Best") {
else if (cell?.textLabel?.text == "Best") {
self.delegate?.categoriesViewControllerDidSelecteFilter(self, filer: .Best, title: "HN:Best")
}

Expand Down
14 changes: 7 additions & 7 deletions SwiftHN/ViewControllers/DetailViewController.swift
Expand Up @@ -45,7 +45,7 @@ class DetailViewController: HNTableViewController {
cellHeightCache = []
for comment : AnyObject in comments {
if let realComment = comment as? Comment {
var height = CommentsCell.heightForText(realComment.text!, bounds: self.tableView.bounds, level: realComment.depth!)
var height = CommentsCell.heightForText(realComment.text!, bounds: self.tableView.bounds, level: realComment.depth)
cellHeightCache.append(height)
}
}
Expand All @@ -62,7 +62,7 @@ class DetailViewController: HNTableViewController {
}


override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
if (indexPath.section == 0) {
var title: NSString = self.post.title!
Expand All @@ -71,11 +71,11 @@ class DetailViewController: HNTableViewController {
return self.cellHeightCache[indexPath.row] as CGFloat
}

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}

override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 0) {
return 1
}
Expand All @@ -87,11 +87,11 @@ class DetailViewController: HNTableViewController {
return 0
}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if (indexPath.section == 0) {
var cell = tableView.dequeueReusableCellWithIdentifier(NewsCellsId) as? NewsCell
cell!.post = self.post
return cell
return cell!
}

var cell = tableView.dequeueReusableCellWithIdentifier(CommentsCellId) as CommentsCell!
Expand All @@ -101,7 +101,7 @@ class DetailViewController: HNTableViewController {
return cell
}

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "toWebview") {
var destination = segue.destinationViewController as WebviewController
destination.post = self.post
Expand Down
30 changes: 16 additions & 14 deletions SwiftHN/ViewControllers/NewsViewController.swift
Expand Up @@ -92,11 +92,11 @@ class NewsViewController: HNTableViewController, NewsCellDelegate, CategoriesVie
}

func onRightButton() {
var navCategories = self.storyboard.instantiateViewControllerWithIdentifier("categoriesNavigationController") as UINavigationController
var navCategories = self.storyboard?.instantiateViewControllerWithIdentifier("categoriesNavigationController") as UINavigationController
var categoriesVC = navCategories.visibleViewController as CategoriesViewController
categoriesVC.delegate = self
var popController = UIPopoverController(contentViewController: navCategories)
popController.presentPopoverFromBarButtonItem(self.navigationItem.rightBarButtonItem,
popController.presentPopoverFromBarButtonItem(self.navigationItem.rightBarButtonItem!,
permittedArrowDirections: UIPopoverArrowDirection.Any,
animated: true)

Expand Down Expand Up @@ -127,12 +127,12 @@ class NewsViewController: HNTableViewController, NewsCellDelegate, CategoriesVie
Helper.showShareSheet(post, controller: self, barbutton: nil)
}
else if (action!.title == titles[1]) {
var webview = self.storyboard.instantiateViewControllerWithIdentifier("WebviewController") as WebviewController
var webview = self.storyboard?.instantiateViewControllerWithIdentifier("WebviewController") as WebviewController
webview.post = post
self.showDetailViewController(webview, sender: nil)
}
else if (action!.title == titles[2]) {
UIApplication.sharedApplication().openURL(post.url)
UIApplication.sharedApplication().openURL(post.url!)
}
}
}
Expand All @@ -149,38 +149,40 @@ class NewsViewController: HNTableViewController, NewsCellDelegate, CategoriesVie
}

//MARK: TableView Management
override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView!,numberOfRowsInSection section: Int) -> Int {
override func tableView(tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
if (self.datasource != nil) {
return self.datasource.count
}
return 0
}

override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
var title: NSString = (self.datasource[indexPath.row] as Post).title!
return NewsCell.heightForText(title, bounds: self.tableView.bounds)
}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier(NewsCellsId) as? NewsCell
cell!.post = self.datasource[indexPath.row] as Post
cell!.cellDelegate = self
if (loadMoreEnabled && indexPath.row == self.datasource.count-3) {
self.tableView.tableFooterView = self.infiniteScrollingView
loadMore()
}
return cell
return cell!
}

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "toWebview") {
var destination = segue.destinationViewController as WebviewController
destination.post = self.datasource[self.tableView.indexPathsForSelectedRows()[0].row] as Post
if let selectedRows = self.tableView.indexPathsForSelectedRows() {
destination.post = self.datasource[selectedRows[0].row] as Post
}
}
}

Expand All @@ -192,7 +194,7 @@ class NewsViewController: HNTableViewController, NewsCellDelegate, CategoriesVie

}

override func tableView(tableView: UITableView!, editActionsForRowAtIndexPath indexPath: NSIndexPath!) -> [AnyObject]!
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]
{
var readingList = UITableViewRowAction(style: UITableViewRowActionStyle.Normal,
title: "Read\nLater",
Expand All @@ -216,13 +218,13 @@ class NewsViewController: HNTableViewController, NewsCellDelegate, CategoriesVie
//MARK: NewsCellDelegate
func newsCellDidSelectButton(cell: NewsCell, actionType: Int, post: Post) {
if (actionType == NewsCellActionType.Comment.toRaw()) {
var detailVC = self.storyboard.instantiateViewControllerWithIdentifier("DetailViewController") as DetailViewController
var detailVC = self.storyboard?.instantiateViewControllerWithIdentifier("DetailViewController") as DetailViewController
detailVC.post = post
self.showDetailViewController(detailVC, sender: self)
}
else if (actionType == NewsCellActionType.Username.toRaw()) {
if let realUsername = post.username {
var detailVC = self.storyboard.instantiateViewControllerWithIdentifier("UserViewController") as UserViewController
var detailVC = self.storyboard?.instantiateViewControllerWithIdentifier("UserViewController") as UserViewController
detailVC.user = realUsername
self.showDetailViewController(detailVC, sender: self)
}
Expand Down
4 changes: 2 additions & 2 deletions SwiftHN/Views/BorderedButton.swift
Expand Up @@ -53,7 +53,7 @@ import SwiftHNShared

@IBInspectable var labelFontSize: CGFloat = 11.0 {
didSet {
self.button.titleLabel.font = UIFont.systemFontOfSize(labelFontSize)
self.button.titleLabel?.font = UIFont.systemFontOfSize(labelFontSize)
}
}

Expand Down Expand Up @@ -88,7 +88,7 @@ import SwiftHNShared
self.labelFontSize = 11.0

self.button.frame = self.bounds
self.button.titleLabel.textAlignment = .Center
self.button.titleLabel?.textAlignment = .Center
self.button.backgroundColor = UIColor.clearColor()

self.addSubview(self.button)
Expand Down
10 changes: 5 additions & 5 deletions SwiftHNShared/HNKit/HNTableViewController.swift
Expand Up @@ -13,12 +13,12 @@ public class HNTableViewController: UITableViewController {
public var refreshing: Bool = false {
didSet {
if (self.refreshing) {
self.refreshControl.beginRefreshing()
self.refreshControl.attributedTitle = NSAttributedString(string: "Loading...")
self.refreshControl?.beginRefreshing()
self.refreshControl?.attributedTitle = NSAttributedString(string: "Loading...")
}
else {
self.refreshControl.endRefreshing()
self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to Refresh")
self.refreshControl?.endRefreshing()
self.refreshControl?.attributedTitle = NSAttributedString(string: "Pull to Refresh")
}
}
}
Expand All @@ -33,6 +33,6 @@ public class HNTableViewController: UITableViewController {
super.viewDidLoad()

self.refreshControl = UIRefreshControl()
self.refreshControl.addTarget(self, action: "onPullToFresh", forControlEvents: UIControlEvents.ValueChanged)
self.refreshControl?.addTarget(self, action: "onPullToFresh", forControlEvents: UIControlEvents.ValueChanged)
}
}
23 changes: 12 additions & 11 deletions SwiftHNToday/TodayViewController.swift
Expand Up @@ -69,36 +69,36 @@ class TodayViewController: UIViewController, NCWidgetProviding, UITableViewDeleg
}

func onOpenApp() {
self.extensionContext.openURL(NSURL(string:"swifthn://"), completionHandler: nil)
self.extensionContext!.openURL(NSURL(string:"swifthn://"), completionHandler: nil)
}

//MARK: TableView Management
func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}


func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.expanded {
return self.posts.count
}
return self.posts.count > 5 ? 5 : self.posts.count
}

func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 55.0
}

func tableView(tableView: UITableView!, heightForFooterInSection section: Int) -> CGFloat {
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
if self.expanded {
return 0
}
return 60.0
}

func tableView(tableView: UITableView!, viewForFooterInSection section: Int) -> UIView! {
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView {
if self.expanded {
return nil
return UIView(frame: CGRectZero)
}
var view = UIVisualEffectView(effect: UIVibrancyEffect.notificationCenterVibrancyEffect())
view.frame = CGRectMake(0, 0, self.tableView.frame.size.width, 30.0)
Expand All @@ -122,15 +122,16 @@ class TodayViewController: UIViewController, NCWidgetProviding, UITableViewDeleg
return view
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = self.tableView.dequeueReusableCellWithIdentifier(todayCellId) as? TodayWidgetCell
var post = self.posts[indexPath.row] as Post
cell!.post = post
return cell
return cell!
}

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
func tableView(tableView: UITableView
, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var post = self.posts[indexPath.row] as Post
self.extensionContext.openURL(post.url!, completionHandler: nil)
self.extensionContext!.openURL(post.url!, completionHandler: nil)
}
}
4 changes: 1 addition & 3 deletions SwiftHNToday/TodayWidgetCell.swift
Expand Up @@ -22,9 +22,7 @@ class TodayWidgetCell: UITableViewCell {
var post: Post! {
didSet {
self.postTitleLabel.text = self.post.title!
if let realPoint = self.post.points {
self.postVoteLabel.text = String(realPoint)
}
self.postVoteLabel.text = String(self.post.points)
self.postSubtitleLabel.text = self.post.domain! + " - " + self.post.prettyTime!
}
}
Expand Down

0 comments on commit e30d97c

Please sign in to comment.