Skip to content

Commit

Permalink
Support for Swift 1.0. Fixes objcio#4 (compilation issues in Xcode 6.…
Browse files Browse the repository at this point in the history
…1 and above).
  • Loading branch information
Srdan Rasic committed Feb 19, 2015
1 parent 59481f2 commit 75c77fb
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

extension NSCalendar {
class func gregorianCalendar() -> NSCalendar {
return NSCalendar(calendarIdentifier: NSGregorianCalendar)
return NSCalendar(calendarIdentifier: NSGregorianCalendar)!
}

func dateWithYear(year: Int, month: Int, day: Int) -> NSDate {
Expand All @@ -19,33 +19,33 @@ extension NSCalendar {
components.month = month
components.day = day
components.hour = 12
return dateFromComponents(components)
return dateFromComponents(components)!
}

func dateForTomorrowRelativeToToday(today: NSDate) -> NSDate {
let tomorrowComponents = NSDateComponents()
tomorrowComponents.day = 1
return dateByAddingComponents(tomorrowComponents, toDate: today, options: nil)
return dateByAddingComponents(tomorrowComponents, toDate: today, options: nil)!
}

func dateForEndOfWeekWithDate(date: NSDate) -> NSDate {
let daysRemainingThisWeek = daysRemainingInWeekWithDate(date)
let remainingDaysComponent = NSDateComponents()
remainingDaysComponent.day = daysRemainingThisWeek
return dateByAddingComponents(remainingDaysComponent, toDate: date, options: nil)
return dateByAddingComponents(remainingDaysComponent, toDate: date, options: nil)!
}

func dateForBeginningOfDay(date: NSDate) -> NSDate {
let newComponent = components((NSCalendarUnit.YearCalendarUnit | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay), fromDate: date)
let newDate = dateFromComponents(newComponent)
return newDate
return newDate!
}

func dateForEndOfDay(date: NSDate) -> NSDate {
let components = NSDateComponents()
components.day = 1
let toDate = dateForBeginningOfDay(date)
let nextDay = dateByAddingComponents(components, toDate: toDate, options: nil)
let nextDay = dateByAddingComponents(components, toDate: toDate, options: nil)!
let endDay = nextDay.dateByAddingTimeInterval(-1)
return nextDay
}
Expand All @@ -61,8 +61,8 @@ extension NSCalendar {
func dateForEndOfFollowingWeekWithDate(date: NSDate) -> NSDate {
let endOfWeek = dateForEndOfWeekWithDate(date)
let nextWeekComponent = NSDateComponents()
nextWeekComponent.setWeek(1)
let followingWeekDate = dateByAddingComponents(nextWeekComponent, toDate: endOfWeek, options: nil)
nextWeekComponent.weekOfMonth = 1
let followingWeekDate = dateByAddingComponents(nextWeekComponent, toDate: endOfWeek, options: nil)!
return followingWeekDate
}

Expand All @@ -81,15 +81,15 @@ extension NSCalendar {
func isDate(date: NSDate, duringSameWeekAsDate: NSDate) -> Bool {
let dateComponents = components(NSCalendarUnit.WeekCalendarUnit, fromDate: date)
let duringSameWeekComponents = components(NSCalendarUnit.WeekCalendarUnit, fromDate: duringSameWeekAsDate)
let result = dateComponents.week() == duringSameWeekComponents.week()
let result = dateComponents.weekOfMonth == duringSameWeekComponents.weekOfMonth
return result
}

func isDate(date: NSDate, duringWeekAfterDate: NSDate) -> Bool {
let nextWeek = dateForEndOfFollowingWeekWithDate(duringWeekAfterDate)
let dateComponents = components(NSCalendarUnit.WeekCalendarUnit, fromDate: date)
let nextWeekComponents = components(NSCalendarUnit.WeekCalendarUnit, fromDate: nextWeek)
let result = dateComponents.week() == nextWeekComponents.week()
let result = dateComponents.weekOfMonth == nextWeekComponents.weekOfMonth
return result
}

Expand Down
16 changes: 8 additions & 8 deletions VIPER-SWIFT/Classes/Common/Store/CoreDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class CoreDataStore : NSObject {
var managedObjectModel : NSManagedObjectModel?
var managedObjectContext : NSManagedObjectContext?

init() {
override init() {
managedObjectModel = NSManagedObjectModel.mergedModelFromBundles(nil)

persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel)
persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel!)

let domains = NSSearchPathDomainMask.UserDomainMask
let directory = NSSearchPathDirectory.DocumentDirectory

Expand All @@ -42,25 +42,25 @@ class CoreDataStore : NSObject {
managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.MainQueueConcurrencyType)
managedObjectContext!.persistentStoreCoordinator = persistentStoreCoordinator
managedObjectContext!.undoManager = nil

super.init()
}

func fetchEntriesWithPredicate(predicate: NSPredicate, sortDescriptors: AnyObject[], completionBlock: ((ManagedTodoItem[]) -> Void)!) {
func fetchEntriesWithPredicate(predicate: NSPredicate, sortDescriptors: [AnyObject], completionBlock: (([ManagedTodoItem]) -> Void)!) {
let fetchRequest = NSFetchRequest(entityName: "TodoItem")
fetchRequest.predicate = predicate
fetchRequest.sortDescriptors = []

managedObjectContext?.performBlock {
let queryResults = self.managedObjectContext?.executeFetchRequest(fetchRequest, error: nil)
let managedResults = queryResults! as ManagedTodoItem[]
let managedResults = queryResults! as [ManagedTodoItem]
completionBlock(managedResults)
}
}

func newTodoItem() -> ManagedTodoItem {
let entityDescription = NSEntityDescription.entityForName("TodoItem", inManagedObjectContext: managedObjectContext)
let newEntry = NSManagedObject(entity: entityDescription, insertIntoManagedObjectContext: managedObjectContext) as ManagedTodoItem
let entityDescription = NSEntityDescription.entityForName("TodoItem", inManagedObjectContext: managedObjectContext!)
let newEntry = NSManagedObject(entity: entityDescription!, insertIntoManagedObjectContext: managedObjectContext) as ManagedTodoItem

return newEntry
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AddDataManager : NSObject {
var dataStore : CoreDataStore?

func addNewEntry(entry: TodoItem) {
let newEntry = dataStore?.newTodoItem() as ManagedTodoItem
let newEntry = dataStore!.newTodoItem() as ManagedTodoItem
newEntry.name = entry.name
newEntry.date = entry.dueDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Foundation
import UIKit

class AddDismissalTransition : NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(transitionContext: UIViewControllerContextTransitioning!) -> NSTimeInterval {
func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
return 0.72
}

func animateTransition(transitionContext: UIViewControllerContextTransitioning!) {
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) as AddViewController

let finalCenter = CGPointMake(160.0, (fromVC.view.bounds.size.height / 2) - 1000.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Foundation
import UIKit

class AddPresentationTransition: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(transitionContext: UIViewControllerContextTransitioning!) -> NSTimeInterval {
func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
return 0.72
}

func animateTransition(transitionContext: UIViewControllerContextTransitioning!) {
let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)!
let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) as AddViewController

toVC.transitioningBackgroundView.backgroundColor = UIColor.darkGrayColor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import UIKit
class AddViewController: UIViewController, UITextFieldDelegate, AddViewInterface {
var eventHandler : AddModuleInterface?

@IBOutlet var nameTextField : UITextField
@IBOutlet var datePicker : UIDatePicker?
@IBOutlet var nameTextField : UITextField!
@IBOutlet var datePicker : UIDatePicker!

var minimumDate : NSDate = NSDate()
var transitioningBackgroundView : UIView = UIView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class ListInteractor : NSObject, ListInteractorInput {
})
}

func upcomingItemsFromToDoItems(todoItems: TodoItem[]) -> UpcomingItem[] {
func upcomingItemsFromToDoItems(todoItems: [TodoItem]) -> [UpcomingItem] {
let calendar = NSCalendar.autoupdatingCurrentCalendar()

var upcomingItems : UpcomingItem[] = []
var upcomingItems : [UpcomingItem] = []

for todoItem in todoItems {
var dateRelation = calendar.nearTermRelationForDate(todoItem.dueDate, relativeToToday: clock.today())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ protocol ListInteractorInput {
}

protocol ListInteractorOutput {
func foundUpcomingItems(upcomingItems: UpcomingItem[])
func foundUpcomingItems(upcomingItems: [UpcomingItem])
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ import Foundation
class ListDataManager : NSObject {
var coreDataStore : CoreDataStore?

func todoItemsBetweenStartDate(startDate: NSDate, endDate: NSDate, completion: ((TodoItem[]) -> Void)!) {
func todoItemsBetweenStartDate(startDate: NSDate, endDate: NSDate, completion: (([TodoItem]) -> Void)!) {
let calendar = NSCalendar.autoupdatingCurrentCalendar()
let beginning = calendar.dateForBeginningOfDay(startDate)
let end = calendar.dateForEndOfDay(endDate)

let predicate = NSPredicate(format: "(date >= %@) AND (date <= %@)", beginning, end)
let sortDescriptors = []

coreDataStore?.fetchEntriesWithPredicate(predicate,
coreDataStore?.fetchEntriesWithPredicate(predicate!,
sortDescriptors: sortDescriptors,
completionBlock: { entries in
let todoItems = self.todoItemsFromDataStoreEntries(entries)
completion(todoItems)
})
}

func todoItemsFromDataStoreEntries(entries: ManagedTodoItem[]) -> TodoItem[] {
var todoItems : TodoItem[] = []
func todoItemsFromDataStoreEntries(entries: [ManagedTodoItem]) -> [TodoItem] {
var todoItems : [TodoItem] = []

for managedTodoItem in entries {
let todoItem = TodoItem(dueDate: managedTodoItem.date, name: managedTodoItem.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ class ListPresenter : NSObject, ListInteractorOutput, ListModuleInterface, AddMo
listInteractor?.findUpcomingItems()
}

func foundUpcomingItems(upcomingItems: UpcomingItem[]) {
func foundUpcomingItems(upcomingItems: [UpcomingItem]) {
if upcomingItems.count == 0 {
userInterface?.showNoContentMessage()
} else {
updateUserInterfaceWithUpcomingItems(upcomingItems)
}
}

func updateUserInterfaceWithUpcomingItems(upcomingItems: UpcomingItem[]) {
func updateUserInterfaceWithUpcomingItems(upcomingItems: [UpcomingItem]) {
let upcomingDisplayData = upcomingDisplayDataWithItems(upcomingItems)
userInterface?.showUpcomingDisplayData(upcomingDisplayData)
}

func upcomingDisplayDataWithItems(upcomingItems: UpcomingItem[]) -> UpcomingDisplayData {
func upcomingDisplayDataWithItems(upcomingItems: [UpcomingItem]) -> UpcomingDisplayData {
let collection = UpcomingDisplayDataCollection()
collection.addUpcomingItems(upcomingItems)
return collection.collectedDisplayData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import Foundation

struct UpcomingDisplayData : Equatable {
let sections : UpcomingDisplaySection[] = []
let sections : [UpcomingDisplaySection] = []

init(sections: UpcomingDisplaySection[]) {
init(sections: [UpcomingDisplaySection]) {
self.sections = sections
self.sections.unshare()
//self.sections.unshare()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import Foundation

class UpcomingDisplayDataCollection {
let dayFormatter = NSDateFormatter()
var sections : Dictionary<NearTermDateRelation, UpcomingDisplayItem[]> = Dictionary()
var sections : Dictionary<NearTermDateRelation, [UpcomingDisplayItem]> = Dictionary()

init() {
dayFormatter.dateFormat = NSDateFormatter.dateFormatFromTemplate("EEEE", options: 0, locale: NSLocale.autoupdatingCurrentLocale())
}

func addUpcomingItems(upcomingItems: UpcomingItem[]) {
func addUpcomingItems(upcomingItems: [UpcomingItem]) {
for upcomingItem in upcomingItems {
addUpcomingItem(upcomingItem)
}
Expand All @@ -28,11 +28,11 @@ class UpcomingDisplayDataCollection {
}

func addDisplayItem(displayItem: UpcomingDisplayItem, dateRelation: NearTermDateRelation) {
if var realSection : UpcomingDisplayItem[] = sections[dateRelation] {
if var realSection : [UpcomingDisplayItem] = sections[dateRelation] {
realSection.append(displayItem)
sections[dateRelation] = realSection
} else {
var newSection : UpcomingDisplayItem[] = []
var newSection : [UpcomingDisplayItem] = []
newSection.append(displayItem)
sections[dateRelation] = newSection
}
Expand All @@ -53,7 +53,7 @@ class UpcomingDisplayDataCollection {
}

func collectedDisplayData() -> UpcomingDisplayData {
let collectedSections : UpcomingDisplaySection[] = sortedUpcomingDisplaySections()
let collectedSections : [UpcomingDisplaySection] = sortedUpcomingDisplaySections()
return UpcomingDisplayData(sections: collectedSections)
}

Expand All @@ -65,14 +65,14 @@ class UpcomingDisplayDataCollection {
return UpcomingDisplaySection(name: sectionTitle, imageName: imageName, items: items)
}

func sortedUpcomingDisplaySections() -> UpcomingDisplaySection[] {
func sortedUpcomingDisplaySections() -> [UpcomingDisplaySection] {
let keys = sortedNearTermDateRelations()
var displaySections : UpcomingDisplaySection[] = []
var displaySections : [UpcomingDisplaySection] = []

for dateRelation in keys {
var itemArray = sections[dateRelation]

if itemArray {
if (itemArray != nil) {
var displaySection = displaySectionForDateRelation(dateRelation)
displaySections.insert(displaySection, atIndex: displaySections.endIndex)
}
Expand All @@ -81,8 +81,8 @@ class UpcomingDisplayDataCollection {
return displaySections
}

func sortedNearTermDateRelations() -> NearTermDateRelation[] {
var array : NearTermDateRelation[] = []
func sortedNearTermDateRelations() -> [NearTermDateRelation] {
var array : [NearTermDateRelation] = []
array.insert(NearTermDateRelation.Today, atIndex: 0)
array.insert(NearTermDateRelation.Tomorrow, atIndex: 1)
array.insert(NearTermDateRelation.LaterThisWeek, atIndex: 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import Foundation
struct UpcomingDisplaySection : Equatable {
let name : String = ""
let imageName : String = ""
var items : UpcomingDisplayItem[] = []
var items : [UpcomingDisplayItem] = []

init(name: String, imageName: String, items: UpcomingDisplayItem[]?) {
init(name: String, imageName: String, items: [UpcomingDisplayItem]?) {
self.name = name
self.imageName = imageName

if items {
if (items != nil) {
self.items = items!
self.items.unshare()
//self.items.unshare()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ListViewController : UITableViewController, ListViewInterface {
var dataProperty : UpcomingDisplayData?
var strongTableView : UITableView?

@IBOutlet var noContentView : UIView
@IBOutlet var noContentView : UIView!

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -58,7 +58,7 @@ class ListViewController : UITableViewController, ListViewInterface {
tableView.reloadData()
}

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
var numberOfSections = dataProperty?.sections.count

if dataProperty?.sections.count == nil {
Expand All @@ -68,25 +68,25 @@ class ListViewController : UITableViewController, ListViewInterface {
return numberOfSections!
}

override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let upcomingSection = dataProperty?.sections[section]
return upcomingSection!.items.count
}

override func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String! {
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String {
let upcomingSection = dataProperty?.sections[section]
return upcomingSection!.name
}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let upcomingSection = dataProperty?.sections[indexPath.section]
let upcomingItem = upcomingSection!.items[indexPath.row]

let cell = tableView.dequeueReusableCellWithIdentifier(ListEntryCellIdentifier, forIndexPath: indexPath) as UITableViewCell

cell.textLabel.text = upcomingItem.title;
cell.detailTextLabel.text = upcomingItem.dueDate;
cell.imageView.image = UIImage(named: upcomingSection!.imageName)
cell.textLabel!.text = upcomingItem.title;
cell.detailTextLabel!.text = upcomingItem.dueDate;
cell.imageView!.image = UIImage(named: upcomingSection!.imageName)
cell.selectionStyle = UITableViewCellSelectionStyle.None;

return cell
Expand Down

0 comments on commit 75c77fb

Please sign in to comment.