let CurrentDate = NSDate()
let CurrentDateFormatter = NSDateFormatter()
//NSTimeInterval delta = [CurrentDate timeIntervalSinceDate,: testData]
CurrentDateFormatter.locale = NSLocale(localeIdentifier: "UTF-8")
CurrentDateFormatter.timeStyle = .MediumStyle
CurrentDateFormatter.dateStyle = .NoStyle
var timer = NSTimer.scheduledTimerWithTimeInterval(1, target:self, selector: Selector("limitCounter"), userInfo: nil, repeats: false)
//limit.text =
//println(CurrentDateFormatter.stringFromDate(CurrentDate))
}
func notif(){
var dataComp : NSDateComponents = NSDateComponents()
dataComp.year = 2014
dataComp.month = 07
dataComp.day = 26
dataComp.hour = 14
dataComp.minute = 11
dataComp.timeZone = NSTimeZone.systemTimeZone()
var calender : NSCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)
var date : NSDate = calender.dateFromComponents (dataComp)
var notification : UILocalNotification = UILocalNotification()
notification.category = "FIRST_CATEGORY"
notification.alertBody = "aaa"
//notification.alertBody = todoObjects[NSIndexPath! .indexPathForRow(1, inSection: 1)]
notification.fireDate = date
println(todoObjects)
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
//
// ViewController.swift
// SwiftTodo
//
// Created by 石井晃 on 2014/06/03.
// Copyright (c) 2014年 exilias. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var todoObjects = [];
var indexPathForCell : NSIndexPath?
var selectedCell : UITableViewCell?
@IBOutlet var tableView : UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
reloadData()
}
func reloadData() {
todoObjects = Todo.MR_findAll()
tableView.reloadData()
}
@IBAction func didTouchAddButton(sender : AnyObject) {
let sampleTodo: Todo = Todo.MR_createEntity() as Todo // エンティティーを作成する
sampleTodo.title = "title: \(NSDate.date())" // 日付をタイトルにセット
sampleTodo.deadline = NSDate.date() // 現在時刻をセット
// CoreDataに保存する(永続化)
sampleTodo.managedObjectContext.MR_saveToPersistentStoreAndWait()
reloadData()
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
println("numberOfRowsInSection")
return todoObjects.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
println("cellForRowAtIndexPath path:\(indexPath)")
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "TodoCell")
cell.textLabel.text = todoObjects[indexPath.row].title
cell.detailTextLabel.text = "\(todoObjects[indexPath.row].deadline)"
return cell
}
func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) {
if editingStyle == UITableViewCellEditingStyle.Delete {
// Entityの削除
let todoObject: Todo = todoObjects[indexPath.row] as Todo
todoObject.MR_deleteEntity()
todoObject.managedObjectContext.MR_saveToPersistentStoreAndWait()
todoObjects = Todo.MR_findAll()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
}
}
func tableView(tableView: UITableView!, editingStyleForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.Delete;
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
//let selectedCell : UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)
selectedCell = tableView.cellForRowAtIndexPath(indexPath)
indexPathForCell = indexPath
self.performSegueWithIdentifier("toDetailView", sender: indexPath)
}
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
println("segue")
if segue.identifier == "toDetailView" {
segue.destinationViewController
var detailView : DetailViewController = segue!.destinationViewController as DetailViewController
detailView.selectedCell = selectedCell
if let tmpTitle : String? = todoObjects[indexPathForCell!.row].title {
detailView.titleText = todoObjects[indexPathForCell!.row].title
}
detailView.dateText = "\(todoObjects[indexPathForCell!.row].deadline)"
if let tmpTag :String? = todoObjects[indexPathForCell!.row].tag {
detailView.tagText = tmpTag
}
if let tmpMemo : String? = todoObjects[indexPathForCell!.row].memo {
detailView.memoText = tmpMemo
}
}
}
override func di
//
// DetailViewController.swift
// SwiftTodo
//
// Created by Hirotoki on 2014/07/26.
// Copyright (c) 2014年 exilias. All rights reserved.
//
import UIKit
class DetailViewController: UIViewController {
//@IBOutlet var backButton : UIButton?
@IBOutlet var imageView : UIImageView?
@IBOutlet var cellTitle : UILabel?
@IBOutlet var cellDate : UILabel?
@IBOutlet var cellTag : UILabel?
@IBOutlet var cellMemo : UITextView?
@IBAction func backToListPage(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
var selectedCell : UITableViewCell?
var indexPath : NSIndexPath?
var titleText : String?
var dateText : String?
var tagText : String?
var memoText : String?
var img : UIImage?
override func viewDidLoad() {
super.viewDidLoad()
img = UIImage(named: "icon")
if img {
imageView!.image = img
}
if titleText {
cellTitle!.text = titleText
}
if dateText {
cellDate!.text = dateText
}
if tagText {
cellTag!.text = tagText
}
if memoText {
cellMemo!.text = memoText
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}