This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,56 @@
//
// Remind_Before.swift
// SAReminder
//
// Created by Alexei Sitalov on 3/28/16.
// Copyright © 2016 Admin. All rights reserved.
//
import UIKit

class Remind_Before {


static func scheduleBefore(index:Int) -> NSDateComponents {

let dateComponents = NSDateComponents ()

if index == 1 {
dateComponents.minute = -5
} else if index == 2 {
dateComponents.minute = -10
}else if index == 3 {
dateComponents.minute = -15
}else if index == 4 {
dateComponents.minute = -30
} else if index == 5 {
dateComponents.minute = -60
} else if index == 6 {
dateComponents.minute = -1140

}

return dateComponents
}


static func truncateSecondsForDate(fromDate: NSDate) -> NSDate {

let calendar : NSCalendar = NSCalendar.currentCalendar()
let unitFlags : NSCalendarUnit = [.Era, .Year, .Month, .Day, .Hour, .Minute]
let fromDateComponents: NSDateComponents = calendar.components(unitFlags, fromDate: fromDate)

return calendar.dateFromComponents(fromDateComponents)!

}

static func truncateDaysForDate(fromDate: NSDate) -> NSDate {

let calendar: NSCalendar = NSCalendar.currentCalendar()
let unitFlags : NSCalendarUnit = [.Year, .Month, .Day]
let fromDateComponents: NSDateComponents = calendar.components(unitFlags, fromDate: fromDate)

return calendar.dateFromComponents(fromDateComponents)!

}
}

Large diffs are not rendered by default.

Empty file.
@@ -7,26 +7,47 @@
//
import UIKit
import CoreData

let ACTION_ONE_IDENTIFIER : String = "ACTION_ONE_IDENTIFIER"
let ACTION_TWO_IDENTIFIER : String = "ACTION_TWO_IDENTIFIER"

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var myNewDictArray = NSMutableArray ()
// var myNewDictArray = NSMutableArray ()
var indexInteger: Int?
let userDefaults = NSUserDefaults.standardUserDefaults()

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

let userDefaults = NSUserDefaults.standardUserDefaults()
myNewDictArray = userDefaults.mutableArrayValueForKey("alarmArr")


UINavigationBar.appearance().setBackgroundImage(UIImage.init(named: "navigationbar"), forBarMetrics: UIBarMetrics.Default)

LocalNotificationHelper.sharedInstance().registerUserNotification()


return true
}

func callGesturePassword () {

application.registerUserNotificationSettings(UIUserNotificationSettings (forTypes: UIUserNotificationType.Alert, categories: nil))
if (userDefaults.objectForKey("gesturePassword") != nil && userDefaults.objectForKey("password")?.boolValue == true ) {

let controller: YLCheckToUnlockViewController = YLCheckToUnlockViewController()
self.window?.rootViewController?.presentViewController(controller, animated: true, completion: nil)

}
}

return true
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {


}

func applicationWillResignActive(application: UIApplication) {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
@@ -41,13 +62,108 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func applicationDidBecomeActive(application: UIApplication) {

if userDefaults.objectForKey("password") == nil{
userDefaults.setBool(false, forKey: "password")
}

if userDefaults.objectForKey("switch") == nil {
userDefaults.setBool(false, forKey: "switch")
}
print("remaining time == \(userDefaults.objectForKey("remaining_time"))")

UIApplication.sharedApplication().applicationIconBadgeNumber = 0

self.callGesturePassword()
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


lazy var applicationDocumentsDirectory: NSURL = {
// The directory the application uses to store the Core Data store file. This code uses a directory named "-11.coreshit" in the application's documents Application Support directory.
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1]
}()

lazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
let modelURL = NSBundle.mainBundle().URLForResource("CoreDataModel", withExtension: "momd")!
return NSManagedObjectModel(contentsOfURL: modelURL)!
}()


lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
// Create the coordinator and store
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("SingleViewCoreData.sqlite")
var failureReason = "There was an error creating or loading the application's saved data."
do {
try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
} catch {
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason

dict[NSUnderlyingErrorKey] = error as NSError
let wrappedError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)")
abort()
}

return coordinator
}()

lazy var managedObjectContext: NSManagedObjectContext = {
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
let coordinator = self.persistentStoreCoordinator
var managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
managedObjectContext.persistentStoreCoordinator = coordinator
return managedObjectContext
}()

// MARK: - Core Data Saving support
func saveContext () {
if managedObjectContext.hasChanges {
do {
try managedObjectContext.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
NSLog("Unresolved error \(nserror), \(nserror.userInfo)")
abort()
}
}
}



func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void) {

if identifier == ACTION_ONE_IDENTIFIER {
print("action one - tapped")

NSNotificationCenter.defaultCenter().postNotificationName(ACTION_ONE_IDENTIFIER, object: nil)

}else if identifier == ACTION_TWO_IDENTIFIER {
print("action two - tapped")

NSNotificationCenter.defaultCenter().postNotificationName(ACTION_TWO_IDENTIFIER, object: nil)
}

completionHandler()
}

}




@@ -1,63 +1,75 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-Small@2x-1.png",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-Small@3x.png",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-40@2x.png",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-40@3x.png",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-60@2x.png",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-60@3x.png",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-Small.png",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-Small@2x.png",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-40.png",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-40@2x-1.png",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-76.png",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-76@2x.png",
"scale" : "2x"
},
{
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,142 @@
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "8.0",
"subtype" : "736h",
"scale" : "3x"
},
{
"orientation" : "landscape",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "8.0",
"subtype" : "736h",
"scale" : "3x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "8.0",
"subtype" : "667h",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"subtype" : "retina4",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"subtype" : "retina4",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "child-selected.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "child-selected@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "child-selected@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "child.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "child@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "child@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "phone-selected.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "phone-selected@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "phone-selected@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "phone.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "phone@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "phone@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "shopping-cart-selected.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "shopping-cart-selected@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "shopping-cart-selected@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "shopping-cart.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "shopping-cart@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "shopping-cart@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "travel-selected.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "travel-selected@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "travel-selected@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "travel.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "travel@2x.png"
},
{
"idiom" : "universal",
"scale" : "3x",
"filename" : "travel@3x.png"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="14F1605" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
<!--View Controller-->
@@ -14,14 +15,31 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="i6+launchscreen.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="MnS-qX-gNY">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<animations/>
</imageView>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="MnS-qX-gNY" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leadingMargin" constant="-20" id="EUE-V4-ymM"/>
<constraint firstItem="xb3-aO-Qok" firstAttribute="top" secondItem="MnS-qX-gNY" secondAttribute="bottom" id="hkV-Zy-h2H"/>
<constraint firstAttribute="trailingMargin" secondItem="MnS-qX-gNY" secondAttribute="trailing" constant="-20" id="sMJ-1s-TV6"/>
<constraint firstItem="MnS-qX-gNY" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="topMargin" id="wl1-eI-D2i"/>
</constraints>
</view>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina55"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<image name="i6+launchscreen.jpg" width="621" height="1104"/>
</resources>
</document>

Large diffs are not rendered by default.

@@ -0,0 +1,23 @@
//
// BasicViewController.h
// Example
//
// Created by Jonathan Tribouharet.
//

#import <UIKit/UIKit.h>

#import <JTCalendar/JTCalendar.h>

@interface BasicViewController : UIViewController <JTCalendarDelegate>

@property (weak, nonatomic) IBOutlet JTCalendarMenuView *calendarMenuView;
@property (weak, nonatomic) IBOutlet JTHorizontalCalendarView *calendarContentView;

@property (strong, nonatomic) JTCalendarManager *calendarManager;

- (NSArray*)getEntityDescriptionArray;

//@property (weak, nonatomic) IBOutlet NSLayoutConstraint *calendarContentViewHeight;

@end
@@ -0,0 +1,317 @@
//
// BasicViewController.m
// Example
//
// Created by Jonathan Tribouharet.
//

#import "BasicViewController.h"
#import <CoreData/CoreData.h>
#import "SAReminder-swift.h"


@interface BasicViewController() <NSFetchedResultsControllerDelegate> {

NSMutableDictionary *_eventsByDate;

NSDate *_todayDate;
NSDate *_minDate;
NSDate *_maxDate;

NSDate *_dateSelected;
NSDate *_newDate1;
}

@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *context;

@end

@implementation BasicViewController

- (void)initializeFetchedResultsController
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Notes"];

NSSortDescriptor *lastNameSort = [NSSortDescriptor sortDescriptorWithKey:@"dateInDateFormat" ascending:YES];
[request setPropertiesToFetch:@[@"dateInDateFormat"]];

[request setSortDescriptors:@[lastNameSort]];

// NSManagedObjectContext *moc = …; //Retrieve the main queue NSManagedObjectContext

[self setFetchedResultsController:[[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.context sectionNameKeyPath:nil cacheName:nil]];
[[self fetchedResultsController] setDelegate:self];

NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Failed to initialize FetchedResultsController: %@\n%@", [error localizedDescription], [error userInfo]);
abort();
}
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(!self){
return nil;
}

self.title = @"Basic";

return self;
}

#pragma mark - Buttons callback

- (IBAction)didGoTodayTouch
{
[_calendarManager setDate:_todayDate];
}

- (IBAction)didChangeModeTouch
{
_calendarManager.settings.weekModeEnabled = !_calendarManager.settings.weekModeEnabled;
[_calendarManager reload];

CGFloat newHeight = 300;
if(_calendarManager.settings.weekModeEnabled){
newHeight = 85.;
}

//self.calendarContentViewHeight.constant = newHeight;
[self.view layoutIfNeeded];
}

#pragma mark - CalendarManager delegate

// Exemple of implementation of prepareDayView method
// Used to customize the appearance of dayView
- (void)calendar:(JTCalendarManager *)calendar prepareDayView:(JTCalendarDayView *)dayView
{

// Today
if([_calendarManager.dateHelper date:[NSDate date] isTheSameDayThan:dayView.date]){
dayView.circleView.hidden = NO;
dayView.circleView.backgroundColor = [UIColor blueColor];
dayView.dotView.backgroundColor = [UIColor whiteColor];
dayView.textLabel.textColor = [UIColor whiteColor];
}
// Selected date
else if(_dateSelected && [_calendarManager.dateHelper date:_dateSelected isTheSameDayThan:dayView.date]){
dayView.circleView.hidden = NO;
dayView.circleView.backgroundColor = [UIColor redColor];
dayView.dotView.backgroundColor = [UIColor whiteColor];
dayView.textLabel.textColor = [UIColor whiteColor];
}
// Other month
else if(![_calendarManager.dateHelper date:_calendarContentView.date isTheSameMonthThan:dayView.date]){
dayView.circleView.hidden = YES;
dayView.dotView.backgroundColor = [UIColor redColor];
dayView.textLabel.textColor = [UIColor brownColor];
}
// Another day of the current month
else{
dayView.circleView.hidden = YES;
dayView.dotView.backgroundColor = [UIColor redColor];
dayView.textLabel.textColor = [UIColor blackColor];
}

if([self haveEventForDay:dayView.date]){
dayView.dotView.hidden = NO;
}
else{
dayView.dotView.hidden = YES;
}
}

- (void)calendar:(JTCalendarManager *)calendar didTouchDayView:(JTCalendarDayView *)dayView
{
_dateSelected = dayView.date;

_newDate1 = [_dateSelected dateByAddingTimeInterval:60*60*24];

// Animation for the circleView
dayView.circleView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1);
[UIView transitionWithView:dayView
duration:.3
options:0
animations:^{
dayView.circleView.transform = CGAffineTransformIdentity;
[_calendarManager reload];
} completion:nil];



[self compareDates];

// Load the previous or next page if touch a day from another month
if(![_calendarManager.dateHelper date:_calendarContentView.date isTheSameMonthThan:dayView.date]){
if([_calendarContentView.date compare:dayView.date] == NSOrderedAscending){
[_calendarContentView loadNextPageWithAnimation];
}
else{
[_calendarContentView loadPreviousPageWithAnimation];
}
}
}

#pragma mark - CalendarManager delegate - Page mangement

// Used to limit the date for the calendar, optional
- (BOOL)calendar:(JTCalendarManager *)calendar canDisplayPageWithDate:(NSDate *)date
{
return [_calendarManager.dateHelper date:date isEqualOrAfter:_minDate andEqualOrBefore:_maxDate];
}

- (void)calendarDidLoadNextPage:(JTCalendarManager *)calendar
{
// NSLog(@"Next page loaded");
}

- (void)calendarDidLoadPreviousPage:(JTCalendarManager *)calendar
{
// NSLog(@"Previous page loaded");
}

#pragma mark - Fake data

- (void)createMinAndMaxDate
{
_todayDate = [NSDate date];

// Min date will be 2 month before today
_minDate = [_calendarManager.dateHelper addToDate:_todayDate months:0];

// Max date will be 2 month after today
_maxDate = [_calendarManager.dateHelper addToDate:_todayDate months:5];
}

// Used only to have a key for _eventsByDate
- (NSDateFormatter *)dateFormatter
{
static NSDateFormatter *dateFormatter;
if(!dateFormatter){
dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"dd-MM-yyyy";
}

return dateFormatter;
}

- (BOOL)haveEventForDay:(NSDate *)date
{
NSString *key = [[self dateFormatter] stringFromDate:date];

if(_eventsByDate[key] && [_eventsByDate[key] count] > 0){
return YES;
}

return NO;

}

- (NSArray*)getEntityDescriptionArray {

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Notes" inManagedObjectContext:_context];

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:@[@"dateInDateFormat"]];

// Execute the fetch.
NSError *error;
NSArray *objects = [_context executeFetchRequest:request error:&error];
if (objects == nil) {
// Handle the error.
}

return objects;
}

- (void)viewDidLoad
{
[super viewDidLoad];

self.view.backgroundColor = [UIColor colorWithPatternImage:[GetBackgroundImage getImage]];
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar"];

self.context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];

_calendarManager = [JTCalendarManager new];
_calendarManager.delegate = self;
[self getEntityDescriptionArray];
// Generate random events sort by date using a dateformatter for the demonstration
[self createRandomEvents];

// Create a min and max date for limit the calendar, optional
[self createMinAndMaxDate];

[_calendarManager setMenuView:_calendarMenuView];
[_calendarManager setContentView:_calendarContentView];
[_calendarManager setDate:_todayDate];
}

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

[self getEntityDescriptionArray];
[self createRandomEvents];

}



- (void) compareDates {

for(int i = 0; i < [self.getEntityDescriptionArray count]; ++i){

NSDictionary *dict = [self.getEntityDescriptionArray objectAtIndex:i];
NSDate *dateToCompare = [dict[@"dateInDateFormat"] dateByAddingTimeInterval:60*60*24];

NSCalendar* calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;

NSDateComponents *comp1 = [calendar components:unitFlags fromDate:_newDate1];
NSDateComponents *comp2 = [calendar components:unitFlags fromDate:dateToCompare];

NSDate *dte1 = [calendar dateFromComponents:comp1];
NSDate *dte2 = [calendar dateFromComponents:comp2];

if ([dte1 isEqualToDate:dte2]) {
NSLog(@"equal dates");
NSMutableDictionary *dict = [NSMutableDictionary new];
[dict setValue:dte1 forKey:@"searchDate"];
NSNotification *notification = [NSNotification notificationWithName:@"MyNotification" object:nil userInfo:dict];
[[NSNotificationCenter defaultCenter] postNotification:notification];

[self.tabBarController setSelectedIndex:0];
}


}
}

- (void)createRandomEvents
{

_eventsByDate = [NSMutableDictionary new];

for(int i = 0; i < [self.getEntityDescriptionArray count]; ++i){

NSDictionary *dict = [self.getEntityDescriptionArray objectAtIndex:i];

NSString *key = [[self dateFormatter] stringFromDate:dict[@"dateInDateFormat"]]; // randomDate IN STRING FORMAT

if(!_eventsByDate[key]){
_eventsByDate[key] = [NSMutableArray new];
}

[_eventsByDate[key] addObject:dict];
}
}

@end
@@ -30,11 +30,12 @@
<array>
<string>armv7</string>
</array>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
@@ -0,0 +1,144 @@
/*
The MIT License (MIT)
Copyright (c) 2015 AhmetKeskin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import Foundation
import AVKit

class LocalNotificationHelper: NSObject {

let LOCAL_NOTIFICATION_CATEGORY : String = "LocalNotificationCategory"

// MARK: - Shared Instance
class func sharedInstance() -> LocalNotificationHelper {
struct Singleton {
static var sharedInstance = LocalNotificationHelper()
}
return Singleton.sharedInstance
}

// MARK: - Schedule Notification
func scheduleNotificationWithKey(key: String, title: String, message: String, seconds: NSDate, userInfo: [NSObject: AnyObject]?) {
// let date = NSDate(timeIntervalSinceNow: NSTimeInterval(seconds)!)
let date = NSDate ()
let notification = notificationWithTitle(key, title: title, message: message, date: date, userInfo: userInfo, soundName: nil, hasAction: true)
notification.category = LOCAL_NOTIFICATION_CATEGORY
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

func scheduleNotificationWithKey(key: String, title: String, message: String, date: NSDate, userInfo: [NSObject: AnyObject]?){
let notification = notificationWithTitle(key, title: title, message: message, date: date, userInfo: ["key": key], soundName: nil, hasAction: true)
notification.category = LOCAL_NOTIFICATION_CATEGORY
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

func cancelNotificationWithKey(key: String, title: String, message: String, date: NSDate, userInfo: [NSObject: AnyObject]?){
let notification = notificationWithTitle(key, title: title, message: message, date: date, userInfo: ["key": key], soundName: nil, hasAction: true)
notification.category = LOCAL_NOTIFICATION_CATEGORY
UIApplication.sharedApplication().cancelLocalNotification(notification)
}

func scheduleNotificationWithKey(key: String, title: String, message: String, seconds: Double, soundName: String, userInfo: [NSObject: AnyObject]?){
let date = NSDate(timeIntervalSinceNow: NSTimeInterval(seconds))
let notification = notificationWithTitle(key, title: title, message: message, date: date, userInfo: ["key": key], soundName: soundName, hasAction: true)
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

func scheduleNotificationWithKey(key: String, title: String, message: String, date: NSDate, soundName: String, userInfo: [NSObject: AnyObject]?){
let notification = notificationWithTitle(key, title: title, message: message, date: date, userInfo: ["key": key], soundName: soundName, hasAction: true)
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

// MARK: - Present Notification
func presentNotificationWithKey(key: String, title: String, message: String, soundName: String, userInfo: [NSObject: AnyObject]?) {
let notification = notificationWithTitle(key, title: title, message: message, date: nil, userInfo: ["key": key], soundName: nil, hasAction: true)
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}

// MARK: - Create Notification
func notificationWithTitle(key : String, title: String, message: String, date: NSDate?, userInfo: [NSObject: AnyObject]?, soundName: String?, hasAction: Bool) -> UILocalNotification {

var dct : Dictionary<String,AnyObject> = userInfo as! Dictionary<String,AnyObject>
dct["key"] = NSString(string: key) as String

let notification = UILocalNotification()
notification.alertAction = title
notification.alertBody = message
notification.userInfo = dct
notification.soundName = soundName ?? UILocalNotificationDefaultSoundName
notification.fireDate = date
notification.hasAction = hasAction
notification.applicationIconBadgeNumber = 1
return notification
}

func getNotificationWithKey(key : String) -> UILocalNotification {

var notif : UILocalNotification?

for notification in UIApplication.sharedApplication().scheduledLocalNotifications! where notification.userInfo!["key"] as! String == key{
notif = notification
break
}

return notif!
}

func cancelNotification(key : String){

for notification in UIApplication.sharedApplication().scheduledLocalNotifications! where notification.userInfo!["key"] as! String == key{
UIApplication.sharedApplication().cancelLocalNotification(notification)
break
}
}

func getAllNotifications() -> [UILocalNotification]? {
return UIApplication.sharedApplication().scheduledLocalNotifications
}

func cancelAllNotifications() {
UIApplication.sharedApplication().cancelAllLocalNotifications()
}

func registerUserNotificationWithActionButtons(actions actions : [UIUserNotificationAction]){

let category = UIMutableUserNotificationCategory()
category.identifier = LOCAL_NOTIFICATION_CATEGORY

category.setActions(actions, forContext: UIUserNotificationActionContext.Default)

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: NSSet(object: category) as? Set<UIUserNotificationCategory>)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}

func registerUserNotification(){

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}

func createUserNotificationActionButton(identifier identifier : String, title : String) -> UIUserNotificationAction{

let actionButton = UIMutableUserNotificationAction()
actionButton.identifier = identifier
actionButton.title = title
actionButton.activationMode = UIUserNotificationActivationMode.Background
actionButton.authenticationRequired = true
actionButton.destructive = false

return actionButton
}

}
@@ -0,0 +1,25 @@
//
// Notes.swift
//
//
// Created by Alexei Sitalov on 3/23/16.
//
//
import Foundation
import CoreData


class Notes: NSManagedObject {

@NSManaged var buttonName: String?
@NSManaged var contentText: String?
@NSManaged var date: String?
@NSManaged var status: String?
@NSManaged var titleText: String?
@NSManaged var index: NSNumber?
@NSManaged var dateInDateFormat: NSDate?
@NSManaged var someTimeBefore: NSDate?
@NSManaged var searchDate: NSDate?

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -4,11 +4,14 @@

#import "HHAlertView.h"

//#import "MenuItem.h"
#import "PCStackMenu.h"
#import "PCStackMenuItem.h"
#import "SWRevealViewController.h"
#import "SideBarTableViewController.h"
#import "YLSwipeLockView.h"
#import "YLSwipeLockNodeView.h"
#import "YLCheckToUnlockViewController.h"
#import "YLInitSwipePasswordController.h"
#import "BasicViewController.h"




@@ -540,21 +540,21 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];

if ( _dragging || self.state == UIGestureRecognizerStateFailed)
return;

const int kDirectionPanThreshold = 5;

UITouch *touch = [touches anyObject];
CGPoint nowPoint = [touch locationInView:self.view];
if (abs(nowPoint.x - _beginPoint.x) > kDirectionPanThreshold) _dragging = YES;
else if (abs(nowPoint.y - _beginPoint.y) > kDirectionPanThreshold) self.state = UIGestureRecognizerStateFailed;
}
//- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
//{
// [super touchesMoved:touches withEvent:event];
//
// if ( _dragging || self.state == UIGestureRecognizerStateFailed)
// return;
//
// const int kDirectionPanThreshold = 5;
//
// UITouch *touch = [touches anyObject];
// CGPoint nowPoint = [touch locationInView:self.view];

// if (abs(nowPoint.x - _beginPoint.x) > kDirectionPanThreshold) _dragging = YES;
// else if (abs(nowPoint.y - _beginPoint.y) > kDirectionPanThreshold) self.state = UIGestureRecognizerStateFailed;
//}

@end

@@ -741,12 +741,12 @@ - (void)viewDidAppear:(BOOL)animated
}


- (NSUInteger)supportedInterfaceOrientations
{
// we could have simply not implemented this, but we choose to call super to make explicit that we
// want the default behavior.
return [super supportedInterfaceOrientations];
}
//- (NSUInteger)supportedInterfaceOrientations
//{
// // we could have simply not implemented this, but we choose to call super to make explicit that we
// // want the default behavior.
// return [super supportedInterfaceOrientations];
//}


#pragma mark - Public methods and property accessors
@@ -1273,7 +1273,7 @@ - (void)_handleRevealGestureStateEndedWithRecognizer:(UIPanGestureRecognizer *)r
NSTimeInterval duration = _toggleAnimationDuration;

// Velocity driven change:
if (fabsf(velocity) > _quickFlickVelocity)
if (fabs(velocity) > _quickFlickVelocity)
{
// we may need to set the drag position and to adjust the animation duration
CGFloat journey = xLocation;
@@ -1291,7 +1291,7 @@ - (void)_handleRevealGestureStateEndedWithRecognizer:(UIPanGestureRecognizer *)r
}
}

duration = fabsf(journey/velocity);
duration = fabs(journey/velocity);
}

// Position driven change:
@@ -1348,7 +1348,7 @@ - (void)_dispatchPushFrontViewController:(UIViewController *)newFrontViewControl

NSTimeInterval duration = animated?_toggleAnimationDuration:0.0;
NSTimeInterval firstDuration = duration;
int initialPosDif = abs( _frontViewPosition - preReplacementPosition );
int initialPosDif = labs( _frontViewPosition - preReplacementPosition );
if ( initialPosDif == 1 ) firstDuration *= 0.8;
else if ( initialPosDif == 0 ) firstDuration = 0;

@@ -7,103 +7,159 @@
//
import UIKit
import CoreData

class ViewController: UIViewController, UITableViewDelegate {
class ViewController: UIViewController, UITableViewDelegate, NSFetchedResultsControllerDelegate {


@IBOutlet weak var leftBarButton: UIBarButtonItem!
@IBOutlet weak var todoSearchBar: UISearchBar!
@IBOutlet weak var alarmTable: UITableView!
@IBOutlet weak var dateLabel: UILabel!
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let selectNote = Selected_Note()
let createANote = New_Note()
var messageLabel = UILabel()
var searchArray = NSMutableArray()
var isFiltered: Bool?
let revealView = SWRevealViewController ()
let formatter1 = NSDateFormatter ()
let formatter2 = NSDateFormatter ()
let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
let request = NSFetchRequest(entityName: "Notes")
@IBOutlet weak var myImage: UIImageView!
let currentDateFormatter = NSDateFormatter ()


lazy var fetchedResultsController: NSFetchedResultsController = {

let notesFetchRequest = NSFetchRequest(entityName: "Notes")

let primarySortDescriptor = NSSortDescriptor(key: "titleText", ascending: true)
let secondarySortDescriptor = NSSortDescriptor(key: "date", ascending: true)
let thirdSortDescriptor = NSSortDescriptor(key: "buttonName", ascending: true)


notesFetchRequest.sortDescriptors = [primarySortDescriptor, secondarySortDescriptor, thirdSortDescriptor]

let frc = NSFetchedResultsController(
fetchRequest: notesFetchRequest,
managedObjectContext: self.managedObjectContext,
sectionNameKeyPath: nil,
cacheName: nil)

frc.delegate = self

return frc
}()

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "createNote") {
let newNoteVC: New_Note = segue.destinationViewController as! New_Note
newNoteVC.titleText = "Add a note"
selectedIndexPath2 = nil
}
}

@IBOutlet weak var calendarImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()

self.title = "Reminder"

messageLabel = UILabel(frame: CGRectMake(0, 0, 200, 84))
messageLabel.numberOfLines = 4
currentDateFormatter.dateFormat = "d MMM, YYYY"

messageLabel.textAlignment = NSTextAlignment.Center
messageLabel.text = "You don't have any notes. To add a new note click '+' button"

view.backgroundColor = UIColor .groupTableViewBackgroundColor()
self.view.backgroundColor = UIColor(patternImage: GetBackgroundImage.getImage())
view.addSubview(messageLabel)
alarmTable.backgroundColor = UIColor(red: (232.0 / 255.0), green: (166.0 / 255.0), blue: (105.0 / 255.0), alpha: 1.0)

leftBarButton.target = revealView.revealViewController()
leftBarButton.action = "revealToggle:"
self.view!.addGestureRecognizer(revealView.panGestureRecognizer())

formatter1.timeStyle = NSDateFormatterStyle.ShortStyle
formatter1.dateFormat = "MM.dd hh:mm"

formatter2.timeStyle = NSDateFormatterStyle.MediumStyle
formatter2.dateFormat = "MMM dd, hh:mm"
let theDate = NSDate()
let theDateString = currentDateFormatter.stringFromDate(theDate)
dateLabel.text = theDateString

self.tabBarController?.tabBar.backgroundImage = UIImage(named: "tabbar")

do {
try fetchedResultsController.performFetch()
} catch {
print("An error occurred")

}

NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleNotification:", name: "MyNotification", object: nil)

}


override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {

}

override func viewDidLayoutSubviews() {
messageLabel.center = CGPointMake(view.frame.size.width / 2, view.frame.size.height / 2)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
//return 1
if let sections = fetchedResultsController.sections {
return sections.count
}

return 0
}

func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
if isFiltered == true {
return searchArray.count;
if let sections = fetchedResultsController.sections {
let currentSection = sections[section]
return currentSection.numberOfObjects
}
return appDelegate.myNewDictArray.count;

return 0
}


func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
// let cell:UITableViewCell = self.alarmTable.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath!) as UITableViewCell

let cell = alarmTable.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath!) as! Cell
cell.accessoryView = UIImageView(image: UIImage(named: "discIndicator.png"))
cell.backgroundColor = UIColor.clearColor()
let notes = fetchedResultsController.objectAtIndexPath(indexPath!) as! Notes

if appDelegate.myNewDictArray.count > 0 {

let noteText = appDelegate.myNewDictArray.objectAtIndex((indexPath?.row)!) .objectForKey("text")

let alarmText = appDelegate.myNewDictArray.objectAtIndex((indexPath?.row)!) .objectForKey("date")

if (isFiltered == nil) {

// Configure the cell...
cell.titleLabel.text = noteText as? String
cell.alarmLabel.text = alarmText as? String
}

else {

// Configue the cell with filtered results.
cell.titleLabel.text = searchArray.objectAtIndex((indexPath?.row)!).objectForKey("text") as? String
cell.alarmLabel.text = searchArray.objectAtIndex((indexPath?.row)!).objectForKey("date") as? String
}

cell.backgroundColor = UIColor(red: (232.0 / 255.0), green: (166.0 / 255.0), blue: (105.0 / 255.0), alpha: 1.0)
let imageSelected = notes.buttonName
let alarmText = notes.date
let statusImage = notes.status

let dateInDateFormat = formatter1.dateFromString(alarmText!)
let dateInStringFormat = formatter2.stringFromDate(dateInDateFormat!)

cell.titleLabel?.text = notes.titleText
if imageSelected != "" {
cell.myImage.image = UIImage(named: imageSelected!)
}
cell.alarmLabel?.text = dateInStringFormat

if statusImage != "" && statusImage != nil{
cell.statusImage.image = UIImage(named:statusImage!)
cell.backgroundColor = UIColor(red: (160.0 / 255.0), green: (160.0 / 255.0), blue: (160.0 / 255.0), alpha: 0.5)
}


return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

selectedIndex = indexPath.row
selectedIndexPath = indexPath

}

@@ -121,86 +177,157 @@ class ViewController: UIViewController, UITableViewDelegate {
self.alarmTable.setEditing(editing, animated: animated)
}

func setDateFormat(){

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM.dd hh:mm"

}


func tableView(tableView: UITableView,
commitEditingStyle editingStyle: UITableViewCellEditingStyle,
forRowAtIndexPath indexPath: NSIndexPath) {
switch editingStyle {
case .Delete:
// remove the deleted item from the model
appDelegate.myNewDictArray.removeObjectAtIndex(indexPath.row)


// remove the deleted item from the `UITableView`
let notes = fetchedResultsController.objectAtIndexPath(indexPath) as! Notes

let userInfo = ["url" : "www.mobiwise.co"]
LocalNotificationHelper.sharedInstance().cancelNotificationWithKey("mobiwise", title: "view details", message: notes.titleText!, date: notes.dateInDateFormat!, userInfo: userInfo)
LocalNotificationHelper.sharedInstance().cancelNotificationWithKey("mobiwise", title: "view details", message: notes.titleText!, date: notes.someTimeBefore!, userInfo: userInfo)

managedObjectContext.deleteObject(notes)

do {
try notes.managedObjectContext!.save()
} catch {
print(error)
}

self.alarmTable.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
if appDelegate.myNewDictArray.count == 0 {
addAnEmptyView()

let notesFetchRequest = NSFetchRequest(entityName: "Notes")

let count = managedObjectContext.countForFetchRequest(notesFetchRequest, error: nil)

if count == 0
{
addAnEmptyView()
todoSearchBar.userInteractionEnabled = false
}

default:
return
}
}

func searchBar(searchBar: UISearchBar, textDidChange text: String) {

if text == "" {

isFiltered = nil

func filter(text: String) {
if text != "" {
let predicate: NSPredicate = NSPredicate(format: "(titleText CONTAINS[c] %@) OR (date CONTAINS[c] %@)", text, text)
fetchedResultsController.fetchRequest.predicate = predicate
} else {
fetchedResultsController.fetchRequest.predicate = nil
}

do {
try fetchedResultsController.performFetch()
} catch {
print("An error occurred")

else {

self.isFiltered = true

searchArray.removeAllObjects()
searchArray.addObjectsFromArray(appDelegate.myNewDictArray.filteredArrayUsingPredicate(NSPredicate(format: "(text CONTAINS[cd] %@) OR (date CONTAINS[cd] %@)", text, text)))
}
}
alarmTable.reloadData()
}

func searchBar(searchBar: UISearchBar, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
// var resultRange: NSRange = text.rangeOfCharacterFromSet(NSCharacterSet.newlineCharacterSet(), options: NSBackwardsSearch)
// if text.characters.count == 1 && resultRange.location != NSNotFound {
// searchBar.resignFirstResponder()
// return false
// }

func searchBar(searchBar: UISearchBar, textDidChange text: String) {

return true
self.filter(text)
alarmTable.reloadData()
}

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
todoSearchBar.setShowsCancelButton(true, animated: true)
}

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
todoSearchBar.resignFirstResponder()
todoSearchBar.text = nil
todoSearchBar.setShowsCancelButton(false, animated: true)
fetchedResultsController.fetchRequest.predicate = nil

do {
try fetchedResultsController.performFetch()
} catch {
print("An error occurred")
}

alarmTable.reloadData()
}


func dismissKeyBoard () {
todoSearchBar.resignFirstResponder()
func searchBarSearchButtonClicked(searchBar: UISearchBar){
todoSearchBar.resignFirstResponder()
todoSearchBar.setShowsCancelButton(false, animated: true)
}

func removeAnEmptyView(){

alarmTable.hidden = false
messageLabel.hidden = true
calendarImage.hidden = true

}


func addAnEmptyView(){

alarmTable.hidden = true
messageLabel.hidden = false
calendarImage.hidden = false

}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated);
if appDelegate.myNewDictArray.count == 0 {
alarmTable.reloadData()

let notesFetchRequest = NSFetchRequest(entityName: "Notes")

let count = managedObjectContext.countForFetchRequest(notesFetchRequest, error: nil)

if count == 0
{
addAnEmptyView()
todoSearchBar.userInteractionEnabled = false
} else {
removeAnEmptyView()
alarmTable.reloadData()
todoSearchBar.userInteractionEnabled = true
}
alarmTable.reloadData()
self.tabBarController?.tabBar.hidden = false

}

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {

if type != .Delete {
alarmTable.reloadData()
}
}

func performSearch(date: NSDate) {

let predicate: NSPredicate = NSPredicate(format:"searchDate == %@", date)
fetchedResultsController.fetchRequest.predicate = predicate

do {
try fetchedResultsController.performFetch()
} catch {
print("An error occurred")

}

}

func handleNotification(notification: NSNotification) {
performSearch(notification.userInfo?["searchDate"] as! NSDate)
}

}

@@ -0,0 +1,13 @@
//
// YLCheckToUnlockViewController.h
// YLSwipeLockViewDemo
//
// Created by 肖 玉龙 on 15/2/28.
// Copyright (c) 2015年 Yulong Xiao. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface YLCheckToUnlockViewController : UIViewController

@end
@@ -0,0 +1,111 @@
//
// YLCheckToUnlockViewController.m
// YLSwipeLockViewDemo
//
// Created by 肖 玉龙 on 15/2/28.
// Copyright (c) 2015年 Yulong Xiao. All rights reserved.
//

#import "YLCheckToUnlockViewController.h"
#import "YLSwipeLockView.h"
#import "UIKit/UIKit.h"


@interface YLCheckToUnlockViewController ()<YLSwipeLockViewDelegate>

@property (nonatomic, weak) YLSwipeLockView *lockView;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic) NSUInteger unmatchCounter;
@property (nonatomic, weak) UILabel *counterLabel;


@end

@implementation YLCheckToUnlockViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.view.backgroundColor = [UIColor colorWithRed:35/255.0 green:39/255.0 blue:54/255.0 alpha:1];

UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = @"swipe to unlock";
titleLabel.textColor = [UIColor whiteColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.frame = CGRectMake(10, 60, self.view.bounds.size.width - 20, 20);
titleLabel.font = [UIFont boldSystemFontOfSize:16];
[self.view addSubview:titleLabel];
self.titleLabel = titleLabel;

UILabel *counterLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 160, self.view.bounds.size.width - 20, 20)];
counterLabel.textColor = [UIColor redColor];
counterLabel.textAlignment = NSTextAlignmentCenter;
counterLabel.font = [UIFont systemFontOfSize:14];
[self.view addSubview:counterLabel];
self.counterLabel = counterLabel;
self.counterLabel.hidden = YES;


CGFloat viewWidth = self.view.bounds.size.width - 40;
CGFloat viewHeight = viewWidth;

YLSwipeLockView *lockView = [[YLSwipeLockView alloc] initWithFrame:CGRectMake(20, self.view.bounds.size.height - viewHeight - 40 - 100, viewWidth, viewHeight)];
[self.view addSubview:lockView];

self.lockView = lockView;
self.lockView.delegate = self;

self.unmatchCounter = 5;

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

-(YLSwipeLockViewState)swipeView:(YLSwipeLockView *)swipeView didEndSwipeWithPassword:(NSString *)password
{
NSString *savedPassword = [[NSUserDefaults standardUserDefaults] objectForKey:@"gesturePassword"];
if ([savedPassword isEqualToString:password]) {
[self dismiss];
return YLSwipeLockViewStateNormal;
}else{
self.unmatchCounter--;
if (self.unmatchCounter == 0) {


self.counterLabel.hidden = NO;
self.unmatchCounter = 5;

}else {

self.counterLabel.text = [NSString stringWithFormat:@"Wrong password"];
self.counterLabel.hidden = NO;
}
return YLSwipeLockViewStateWarning;
}
}



- (void)dismissViewController // DISMISSING THE BLOCK SCREEN!!!!!
{
//if you are pushing your viewControler, then use below single line code
// [self.navigationController popViewControllerAnimated:YES];
//if you are presnting ViewController modally. then use below code
//[self dismissModalViewControllerAnimated:YES];

}

-(void)dismiss{

if (self.presentingViewController) {

[self dismissViewControllerAnimated:YES completion:nil];

}
}



@end
@@ -0,0 +1,13 @@
//
// YLInitSwipePasswordController.h
// YLSwipeLockViewDemo
//
// Created by 肖 玉龙 on 15/2/27.
// Copyright (c) 2015年 Yulong Xiao. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface YLInitSwipePasswordController : UIViewController

@end
@@ -0,0 +1,97 @@

// YLInitSwipePasswordController.m
// YLSwipeLockViewDemo
//
// Created by 肖 玉龙 on 15/2/27.
// Copyright (c) 2015年 Yulong Xiao. All rights reserved.
//

#import "YLInitSwipePasswordController.h"
#import "YLSwipeLockView.h"

@interface YLInitSwipePasswordController ()<YLSwipeLockViewDelegate>
@property (nonatomic, weak) YLSwipeLockView *lockView;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, strong) NSString *passwordString;
@property (nonatomic, weak) UIButton *resetButton;
@end

@implementation YLInitSwipePasswordController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithRed:35/255.0 green:39/255.0 blue:54/255.0 alpha:1];

UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = @"set your gesture password";
titleLabel.textColor = [UIColor whiteColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.frame = CGRectMake(40, 60, self.view.bounds.size.width - 80, 20);
titleLabel.font = [UIFont boldSystemFontOfSize:16];
[self.view addSubview:titleLabel];
self.titleLabel = titleLabel;

CGFloat viewWidth = self.view.bounds.size.width - 40;
CGFloat viewHeight = viewWidth;

YLSwipeLockView *lockView = [[YLSwipeLockView alloc] initWithFrame:CGRectMake(20, self.view.bounds.size.height - viewHeight - 40 - 100, viewWidth, viewHeight)];
[self.view addSubview:lockView];

self.lockView = lockView;
self.lockView.delegate = self;

UIButton *resetButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 60, 60, 40, 20)];
[resetButton setTitle:@"reset" forState:UIControlStateNormal];
[resetButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[resetButton addTarget:self action:@selector(reset) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:resetButton];
self.resetButton = resetButton;
self.resetButton.hidden = YES;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

-(YLSwipeLockViewState)swipeView:(YLSwipeLockView *)swipeView didEndSwipeWithPassword:(NSString *)password
{
if (self.passwordString == nil) {
self.passwordString = password;
self.titleLabel.text = @"confirm your gesture password again";
return YLSwipeLockViewStateNormal;
}else if ([self.passwordString isEqualToString:password]){
self.titleLabel.text = @"set succeed";
self.passwordString = nil;

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setObject:password forKey:@"gesturePassword"];

[self performSelector:@selector(dismiss) withObject:nil afterDelay:1];
return YLSwipeLockViewStateSelected;
}else{
self.titleLabel.text = @"different from last time";
self.resetButton.hidden = NO;
return YLSwipeLockViewStateWarning;
}

}

-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}

-(void)dismiss{
if (self.presentingViewController) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}

-(void)reset
{
self.passwordString = nil;
self.titleLabel.text = @"set your gesture password";
self.resetButton.hidden = YES;
}

@end
@@ -0,0 +1,19 @@
//
// YLSwipeLockNodeView.h
// YLSwipeLockViewDemo
//
// Created by 肖 玉龙 on 15/2/12.
// Copyright (c) 2015年 Yulong Xiao. All rights reserved.
//

#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, YLSwipeLockNodeViewStatus) {
YLSwipeLockNodeViewStatusNormal,
YLSwipeLockNodeViewStatusSelected,
YLSwipeLockNodeViewStatusWarning
};

@interface YLSwipeLockNodeView : UIView
@property (nonatomic) YLSwipeLockNodeViewStatus nodeViewStatus;

@end
@@ -0,0 +1,119 @@
//
// YLSwipeLockNodeView.m
// YLSwipeLockViewDemo
//
// Created by 肖 玉龙 on 15/2/12.
// Copyright (c) 2015年 Yulong Xiao. All rights reserved.
//

#import "YLSwipeLockNodeView.h"
#import "YLSwipeLockView.h"
@interface YLSwipeLockNodeView()
@property (nonatomic, strong)CAShapeLayer *outlineLayer;
@property (nonatomic, strong)CAShapeLayer *innerCircleLayer;
@end


@implementation YLSwipeLockNodeView
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.layer addSublayer:self.outlineLayer];
[self.layer addSublayer:self.innerCircleLayer];
self.nodeViewStatus = YLSwipeLockNodeViewStatusNormal;
}
return self;
}

-(void)pan:(UIPanGestureRecognizer *)rec
{
// NSLog(@"what the fuck");
// CGPoint point = [rec locationInView:self];
// NSLog(@"location in view:%f, %f", point.x, point.y);
self.nodeViewStatus = YLSwipeLockNodeViewStatusSelected;
}

-(void)setNodeViewStatus:(YLSwipeLockNodeViewStatus)nodeViewStatus
{
_nodeViewStatus = nodeViewStatus;
switch (_nodeViewStatus) {
case YLSwipeLockNodeViewStatusNormal:
[self setStatusToNormal];
break;
case YLSwipeLockNodeViewStatusSelected:
[self setStatusToSelected];
break;
case YLSwipeLockNodeViewStatusWarning:
[self setStatusToWarning];
break;
default:
break;
}
}

-(void)setStatusToNormal
{
self.outlineLayer.strokeColor = [UIColor whiteColor].CGColor;
self.innerCircleLayer.fillColor = [UIColor clearColor].CGColor;
}

-(void)setStatusToSelected
{
self.outlineLayer.strokeColor = LIGHTBLUE.CGColor;
self.innerCircleLayer.fillColor = LIGHTBLUE.CGColor;
}

-(void)setStatusToWarning
{
self.outlineLayer.strokeColor = [UIColor redColor].CGColor;
self.innerCircleLayer.fillColor = [UIColor redColor].CGColor;

}


-(void)layoutSubviews
{
self.outlineLayer.frame = self.bounds;
UIBezierPath *outlinePath = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
self.outlineLayer.path = outlinePath.CGPath;

CGRect frame = self.bounds;
CGFloat width = frame.size.width / 3;
self.innerCircleLayer.frame = CGRectMake(width, width, width, width);
UIBezierPath *innerPath = [UIBezierPath bezierPathWithOvalInRect:self.innerCircleLayer.bounds];
self.innerCircleLayer.path = innerPath.CGPath;

}

-(CAShapeLayer *)outlineLayer
{
if (_outlineLayer == nil) {
_outlineLayer = [[CAShapeLayer alloc] init];
_outlineLayer.strokeColor = LIGHTBLUE.CGColor;
_outlineLayer.lineWidth = 1.0f;
_outlineLayer.fillColor = [UIColor clearColor].CGColor;
}
return _outlineLayer;
}

-(CAShapeLayer *)innerCircleLayer
{
if (_innerCircleLayer == nil) {
_innerCircleLayer = [[CAShapeLayer alloc] init];
_innerCircleLayer.strokeColor = [UIColor clearColor].CGColor;
_innerCircleLayer.lineWidth = 1.0f;
_innerCircleLayer.fillColor = LIGHTBLUE.CGColor;
}
return _innerCircleLayer;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/

@end
@@ -0,0 +1,27 @@
//
// YLSwipeLockView.h
// YLSwipeLockViewDemo
//
// Created by 肖 玉龙 on 15/2/12.
// Copyright (c) 2015年 Yulong Xiao. All rights reserved.
//

#import <UIKit/UIKit.h>
#define LIGHTBLUE [UIColor colorWithRed:0 green:170/255.0 blue:1 alpha:1]

typedef NS_ENUM(NSUInteger, YLSwipeLockViewState) {
YLSwipeLockViewStateNormal,
YLSwipeLockViewStateWarning,
YLSwipeLockViewStateSelected
};
@protocol YLSwipeLockViewDelegate;

@interface YLSwipeLockView : UIView
@property (nonatomic, weak) id<YLSwipeLockViewDelegate> delegate;
@end


@protocol YLSwipeLockViewDelegate<NSObject>
@optional
-(YLSwipeLockViewState)swipeView:(YLSwipeLockView *)swipeView didEndSwipeWithPassword:(NSString *)password;
@end