I am developing application for tvOS in swift using Xcode 7.3, I had written a Class to split events on the basis of my requirements like -
import UIKit
class SplitEvents: NSObject
{
var eventDisplayArray:NSMutableArray = []
var eventHiddenArray:NSMutableArray = []
var lastMemorisedDate:NSDate?
var tempEventStartDateEndDateArray:NSMutableArray?
func InitialiseFunction (displayArray:NSMutableArray, HiddenArray hiddenArray:NSMutableArray, ResultArray result:NSArray, completionHandler:(NSMutableArray?,NSMutableArray?, NSError?)->Void?) ->Void
{
eventDisplayArray = displayArray
eventHiddenArray = hiddenArray
SplitEvent(result.mutableCopy() as! NSMutableArray)
completionHandler(eventDisplayArray,eventHiddenArray, nil)
}
func SplitEvent(result:NSMutableArray)->Void
{
if(eventDisplayArray.count>0)
{
for event in result
{
for existingEvent in eventDisplayArray
{
if ((existingEvent as! Event).eventID == (event as! Event) .eventID)
{
result.removeObject(event)
break
}
}
}
}
for event in result
{
tempEventStartDateEndDateArray = []
for dict in (event as! Event).eventSatrtEndDateRange
{
tempEventStartDateEndDateArray!.addObject(dict)
}
if (tempEventStartDateEndDateArray!.count>1)
{
event.eventSatrtEndDateRange.removeAllObjects()
var tempStartEndDateArray:NSMutableArray = []
var i:Int = 0
for fisrtDict in tempEventStartDateEndDateArray!
{
let df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd"
if ((fisrtDict["start"] as! NSDate) == (fisrtDict["end"] as! NSDate))
{
tempStartEndDateArray.addObject(fisrtDict)
var currentDate:NSDate = fisrtDict["start"]
var calendar:NSCalendar = NSCalendar().currentCalendar
var dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:fisrtDict["start"], options:0)
if (i+1>=tempEventStartDateEndDateArray.count)
{
event.eventSatrtEndDateRange.removeAllObjects()
var temp:Event = CreateTemporaryObject(event)
if (event.savedEventsEndDates.count>0)
{
if (event.savedEventsEndDates.containsObject(fisrtDict["end"]) == false)
{
temp.attending = ""
}
else
{
temp.attending = event.attending
}
}
else
{
temp.attending = event.attending
}
temp.eventStartDate = empStartEndDateArray[0]["start"]
temp.eventEndDate = tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"]
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray)
GroupObjectArray(temp)
tempStartEndDateArray.removeAllObjects()
}
else
{
var secondDict: NSMutableDictionary = tempEventStartDateEndDateArray[i+1]
if ((currentDate == secondDict["start"]) == false)
{
event.eventSatrtEndDateRange.removeAllObjects()
var temp:Event = CreateTemporaryObject(event)
if (event.savedEventsEndDates.count>0)
{
if (event.savedEventsEndDates.containsObject(fisrtDict["end"]) == false)
{
temp.attending = ""
}
else
{
temp.attending = event.attending
}
}
else
{
temp.attending = event.attending
}
temp.eventStartDate = tempStartEndDateArray[0]["start"]
temp.eventEndDate = tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"]
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray)
GroupObjectArray(temp)
tempStartEndDateArray.removeAllObjects()
}
}
}
else if((fisrtDict["end"] as NSDate).timeIntervalSinceDate(fisrtDict["start"]) > 0 )
{
tempStartEndDateArray.addObject(fisrtDict)
event.eventSatrtEndDateRange.removeAllObjects()
var temp:Event = CreateTemporaryObject(event)
if (event.savedEventsEndDates.count>0)
{
if (event.savedEventsEndDates.containsObject(fisrtDict["end"]) == false)
{
temp.attending = ""
}
else
{
temp.attending = event.attending
}
}
else
{
temp.attending = event.attending
}
temp.eventStartDate = tempStartEndDateArray[0]["start"]
temp.eventEndDate = tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"]
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray)
GroupObjectArray(temp)
tempStartEndDateArray.removeAllObjects()
}
i = i+1
}
}
else
{
GroupObjectArray(event)
}
}
if (result.count>0)
{
if (result.count>=10)
{
self.lastMemorisedDate = result[(result.count-1)].eventEndDate
}
else
{
self.lastMemorisedDate = nil
}
}
ShortArrayByDate()
}
func CreateTemporaryObject(event:Event) ->Event
{
var temp: Event = Event()
temp.hasEventTime=event.hasEventTime
temp.newForUser=event.newForUser
temp.name=event.name
temp.eventID=event.eventID
temp.imageURLString=event.imageURLString
temp.city=event.city
temp.venueID=event.venueID
temp.venueName=event.venueName
temp.distance=event.distance
temp.latitude=event.latitude
temp.savedEventsEndDates=event.savedEventsEndDates
temp.longitude=event.longitude
temp.eventDate=event.eventDate
// temp.eventEndDate=event.eventEndDate;
// temp.eventStartDate=event.eventStartDate;
// temp.attending=event.attending;
temp.trackbackUrlString=event.trackbackUrlString
temp.categories=event.categories
temp.artists=event.artists
temp.schedules=event.schedules
temp.friendsGoing=event.friendsGoing
temp.friendsWantTo=event.friendsWantTo
temp.friends=event.friends
temp.prices=event.prices
temp.currency=event.currency
temp.venue=event.venue
temp.watchImageURLString=event.watchImageURLString
temp.watchImageMobURLString=event.watchImageMobURLString
temp.eventDescription=event.eventDescription
temp.shortURLString=event.shortURLString
return temp
}
func ShortArrayByDate() ->Void
{
var sortDescriptor: NSSortDescriptor = NSSortDescriptor(key: "eventStartDate", ascending: YES)
var sortDescriptors = NSArray(array:sortDescriptor)
var sortedArray: NSArray?
sortedArray = eventHiddenArray.sortedArrayUsingDescriptors(sortDescriptors)
eventHiddenArray = sortedArray.mutableCopy()
// self.eventDisplayArray= [sortedArray mutableCopy];
if (self.lastMemorisedDate)
{
var predicate: NSPredicate = NSPredicate(format: "(eventStartDate =< %@)",lastMemorisedDate)
eventDisplayArray = eventHiddenArray.filter { pred.evaluateWithObject($0) };
}
else
{
self.eventDisplayArray = sortedArray.mutableCopy()
}
}
func GroupObjectArray(event:Event)->Void
{
if (eventHiddenArray == nil)
{
eventHiddenArray = [];
}
self.eventHiddenArray.addObject(event)
}
func GetFirstSlotEventStartEndDate(eventStartDateEndDateArray:NSMutableArray )->NSMutableArray
{
var tempStartEndDateArray:NSMutableArray = [];
var i:Int = 0
for fisrtDict in eventStartDateEndDateArray
{
var df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd"
if (fisrtDict["start"] == fisrtDict ["end"])
{
tempStartEndDateArray.addObject(fisrtDict)
var currentDate: NSDate = fisrtDict["start"];
var calendar: NSCalendar = NSCalendar().currentCalendar
var dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:fisrtDict["start"], options:0)
if (i+1>=eventStartDateEndDateArray.count)
{
break
}
else
{
var secondDict:NSMutableDictionary = eventStartDateEndDateArray[i+1];
if ((currentDate == secondDict ["start"]) == false)
{
break
}
}
}
else if((fisrtDict["end"] as NSDate?).timeIntervalSinceDate(fisrtDict["start"]) > 0 )
{
tempStartEndDateArray.addObject(fisrtDict)
break
}
i = i+1
}
//
return tempStartEndDateArray;
}
func GetFirstSlotEndDate(eventStartDateEndDateArray:NSMutableArray) ->String
{
var firstSlotEventEndDate:String = ""
var i:Int = 0
for fisrtDict in eventStartDateEndDateArray
{
var df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd"
if (fisrtDict["start"] == fisrtDict["end"])
{
var currentDate: NSDate = fisrtDict["start"];
var calendar: NSCalendar = NSCalendar().currentCalendar
var dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1;
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:fisrtDict["start"], options:0);
if (i+1>=eventStartDateEndDateArray.count)
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"])
break;
}
else
{
var secondDict:NSMutableDictionary = eventStartDateEndDateArray[i+1];
if (!(currentDate == secondDict["start"]))
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"])
break;
}
}
}
else if((fisrtDict["end"] as NSDate?).timeIntervalSinceDate(fisrtDict["start"]) > 0 )
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"]);
break;
}
}
return firstSlotEventEndDate;
}
}
when i am including above file in my application Xcode giving me compile time error an internal error occurred . Source editor functionality is limited . Attempting to restore...