发生了内部错误 。源代码编辑器功能有限。正在尝试恢复
an internal error occurred . Source editor functionality is limited . Attempting to restore
我正在使用 Xcode 7.3 在 swift 中为 tvOS 开发应用程序,我写了一个 Class 来根据我的要求拆分事件,例如 -
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([=10=]) };
}
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;
}
}
当我在我的应用程序中包含上述文件时 Xcode 出现编译时错误 an internal error occurred . Source editor functionality is limited . Attempting to restore...
在逐步检查我的代码后,我终于找出了代码中的问题。 If you have more syntax mistakes in your code
swift 2.x Xcode
编译停止显示语法错误并给出错误 an internal error occurred . Source editor functionality is limited . Attempting to restore...
更正后的代码格式为 -
import UIKit
class SplitEvents: NSObject
{
var eventDisplayArray = NSMutableArray()
var eventHiddenArray = NSMutableArray()
var lastMemorisedDate:NSDate?
var tempEventStartDateEndDateArray = NSMutableArray()
func InitialiseFunction (displayArray:NSMutableArray, hiddenArray:NSMutableArray, 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).isEqualToDate((fisrtDict["end"] as! NSDate)))
{
tempStartEndDateArray.addObject(fisrtDict)
var currentDate:NSDate = fisrtDict["start"] as! NSDate
var calendar:NSCalendar = NSCalendar.currentCalendar()
var dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:(fisrtDict["start"] as! NSDate), options:NSCalendarOptions(rawValue: 0))!
if (i+1 >= tempEventStartDateEndDateArray.count)
{
event.eventSatrtEndDateRange.removeAllObjects()
var temp:Event = CreateTemporaryObject(event as! Event)
if ((event as! Event).savedEventsEndDates.count > 0)
{
if ((event as! Event).savedEventsEndDates.containsObject(fisrtDict["end"] as! NSDate ) == false)
{
temp.attending = ""
}
else
{
temp.attending = (event as! Event).attending
}
}
else
{
temp.attending = (event as! Event).attending
}
temp.eventStartDate = ((tempStartEndDateArray[0]["start"]) as! NSDate)
temp.eventEndDate = (tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"] as! NSDate)
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray as [AnyObject])
GroupObjectArray(temp)
tempStartEndDateArray.removeAllObjects()
}
else
{
var secondDict: NSMutableDictionary = tempEventStartDateEndDateArray[i+1] as! NSMutableDictionary
if (currentDate.isEqualToDate(secondDict["start"] as! NSDate) == false)
{
event.eventSatrtEndDateRange.removeAllObjects()
var temp:Event = CreateTemporaryObject(event as! Event)
if ((event as! Event).savedEventsEndDates.count>0)
{
if ((event as! Event).savedEventsEndDates.containsObject(fisrtDict["end"] as! NSDate) == false)
{
temp.attending = ""
}
else
{
temp.attending = (event as! Event).attending
}
}
else
{
temp.attending = (event as! Event).attending
}
temp.eventStartDate = (tempStartEndDateArray[0]["start"] as! NSDate)
temp.eventEndDate = (tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"] as! NSDate)
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray as [AnyObject])
GroupObjectArray(temp as Event)
tempStartEndDateArray.removeAllObjects()
}
}
}
else if((fisrtDict["end"] as! NSDate).timeIntervalSinceDate(fisrtDict["start"] as! NSDate) > 0 )
{
tempStartEndDateArray.addObject(fisrtDict)
(event as! Event).eventSatrtEndDateRange.removeAllObjects()
let temp:Event = CreateTemporaryObject((event as! Event))
if ((event as! Event).savedEventsEndDates.count>0)
{
if ((event as! Event).savedEventsEndDates.containsObject(fisrtDict["end"] as! NSDate) == false)
{
temp.attending = ""
}
else
{
temp.attending = (event as! Event).attending
}
}
else
{
temp.attending = (event as! Event).attending
}
temp.eventStartDate = (tempStartEndDateArray[0]["start"] as! NSDate)
temp.eventEndDate = (tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"] as! NSDate)
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray as [AnyObject])
GroupObjectArray(temp)
tempStartEndDateArray.removeAllObjects()
}
i = i+1
}
}
else
{
GroupObjectArray(event as! Event)
}
}
if (result.count>0)
{
if (result.count>=10)
{
self.lastMemorisedDate = (result[(result.count-1)] as! Event).eventEndDate
}
else
{
self.lastMemorisedDate = nil
}
}
ShortArrayByDate()
}
func CreateTemporaryObject(event:Event) ->Event
{
let 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.eventDescription=event.eventDescription
temp.shortURLString=event.shortURLString
return temp
}
func ShortArrayByDate() ->Void
{
let sortDescriptor: NSSortDescriptor = NSSortDescriptor(key: "eventStartDate", ascending: true)
let sortDescriptors = [sortDescriptor]
let sortedArray:NSArray = eventHiddenArray.sortedArrayUsingDescriptors(sortDescriptors)
eventHiddenArray = sortedArray.mutableCopy() as! NSMutableArray
if (self.lastMemorisedDate != nil)
{
let pred = NSPredicate(format: "eventStartDate =< %@", lastMemorisedDate!)
let displayArray:NSArray = eventHiddenArray.filter { pred.evaluateWithObject([=10=]) } ;
eventDisplayArray = displayArray.mutableCopy() as! NSMutableArray
}
else
{
self.eventDisplayArray = sortedArray.mutableCopy() as! NSMutableArray
}
}
func GroupObjectArray(event:Event)->Void
{
self.eventHiddenArray.addObject(event)
}
func GetFirstSlotEventStartEndDate(eventStartDateEndDateArray:NSMutableArray )->NSMutableArray
{
let tempStartEndDateArray = NSMutableArray();
var i:Int = 0
for fisrtDict in eventStartDateEndDateArray
{
let df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd"
if ((fisrtDict["start"] as! NSDate).isEqualToDate((fisrtDict ["end"] as! NSDate)))
{
tempStartEndDateArray.addObject(fisrtDict)
var currentDate: NSDate = fisrtDict["start"] as! NSDate;
let calendar: NSCalendar = NSCalendar.currentCalendar()
let dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:(fisrtDict["start"] as! NSDate), options:NSCalendarOptions(rawValue: 0))!
if (i+1>=eventStartDateEndDateArray.count)
{
break
}
else
{
let secondDict:NSMutableDictionary = eventStartDateEndDateArray[i+1] as! NSMutableDictionary;
if (currentDate.isEqualToDate(secondDict ["start"] as! NSDate))
{
break
}
}
}
else if((fisrtDict["end"] as! NSDate).timeIntervalSinceDate(fisrtDict["start"] as! NSDate) > 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
{
let df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd"
if ((fisrtDict["start"] as! NSDate).isEqualToDate((fisrtDict ["end"] as! NSDate)))
{
var currentDate: NSDate = fisrtDict["start"] as! NSDate;
let calendar: NSCalendar = NSCalendar.currentCalendar()
let dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1;
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:(fisrtDict["start"] as! NSDate), options:NSCalendarOptions(rawValue: 0))!;
if (i+1>=eventStartDateEndDateArray.count)
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"] as! NSDate)
break;
}
else
{
let secondDict:NSMutableDictionary = eventStartDateEndDateArray[i+1] as! NSMutableDictionary;
if (currentDate.isEqualToDate(secondDict["start"] as! NSDate))
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"] as! NSDate)
break;
}
}
}
else if((fisrtDict["end"] as! NSDate).timeIntervalSinceDate(fisrtDict["start"] as! NSDate) > 0 )
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"] as! NSDate);
break;
}
i = i+1
}
return firstSlotEventEndDate;
}
}
我正在使用 Xcode 7.3 在 swift 中为 tvOS 开发应用程序,我写了一个 Class 来根据我的要求拆分事件,例如 -
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([=10=]) };
}
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;
}
}
当我在我的应用程序中包含上述文件时 Xcode 出现编译时错误 an internal error occurred . Source editor functionality is limited . Attempting to restore...
在逐步检查我的代码后,我终于找出了代码中的问题。 If you have more syntax mistakes in your code
swift 2.x Xcode
编译停止显示语法错误并给出错误 an internal error occurred . Source editor functionality is limited . Attempting to restore...
更正后的代码格式为 -
import UIKit
class SplitEvents: NSObject
{
var eventDisplayArray = NSMutableArray()
var eventHiddenArray = NSMutableArray()
var lastMemorisedDate:NSDate?
var tempEventStartDateEndDateArray = NSMutableArray()
func InitialiseFunction (displayArray:NSMutableArray, hiddenArray:NSMutableArray, 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).isEqualToDate((fisrtDict["end"] as! NSDate)))
{
tempStartEndDateArray.addObject(fisrtDict)
var currentDate:NSDate = fisrtDict["start"] as! NSDate
var calendar:NSCalendar = NSCalendar.currentCalendar()
var dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:(fisrtDict["start"] as! NSDate), options:NSCalendarOptions(rawValue: 0))!
if (i+1 >= tempEventStartDateEndDateArray.count)
{
event.eventSatrtEndDateRange.removeAllObjects()
var temp:Event = CreateTemporaryObject(event as! Event)
if ((event as! Event).savedEventsEndDates.count > 0)
{
if ((event as! Event).savedEventsEndDates.containsObject(fisrtDict["end"] as! NSDate ) == false)
{
temp.attending = ""
}
else
{
temp.attending = (event as! Event).attending
}
}
else
{
temp.attending = (event as! Event).attending
}
temp.eventStartDate = ((tempStartEndDateArray[0]["start"]) as! NSDate)
temp.eventEndDate = (tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"] as! NSDate)
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray as [AnyObject])
GroupObjectArray(temp)
tempStartEndDateArray.removeAllObjects()
}
else
{
var secondDict: NSMutableDictionary = tempEventStartDateEndDateArray[i+1] as! NSMutableDictionary
if (currentDate.isEqualToDate(secondDict["start"] as! NSDate) == false)
{
event.eventSatrtEndDateRange.removeAllObjects()
var temp:Event = CreateTemporaryObject(event as! Event)
if ((event as! Event).savedEventsEndDates.count>0)
{
if ((event as! Event).savedEventsEndDates.containsObject(fisrtDict["end"] as! NSDate) == false)
{
temp.attending = ""
}
else
{
temp.attending = (event as! Event).attending
}
}
else
{
temp.attending = (event as! Event).attending
}
temp.eventStartDate = (tempStartEndDateArray[0]["start"] as! NSDate)
temp.eventEndDate = (tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"] as! NSDate)
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray as [AnyObject])
GroupObjectArray(temp as Event)
tempStartEndDateArray.removeAllObjects()
}
}
}
else if((fisrtDict["end"] as! NSDate).timeIntervalSinceDate(fisrtDict["start"] as! NSDate) > 0 )
{
tempStartEndDateArray.addObject(fisrtDict)
(event as! Event).eventSatrtEndDateRange.removeAllObjects()
let temp:Event = CreateTemporaryObject((event as! Event))
if ((event as! Event).savedEventsEndDates.count>0)
{
if ((event as! Event).savedEventsEndDates.containsObject(fisrtDict["end"] as! NSDate) == false)
{
temp.attending = ""
}
else
{
temp.attending = (event as! Event).attending
}
}
else
{
temp.attending = (event as! Event).attending
}
temp.eventStartDate = (tempStartEndDateArray[0]["start"] as! NSDate)
temp.eventEndDate = (tempStartEndDateArray[(tempStartEndDateArray.count-1)]["end"] as! NSDate)
temp.eventSatrtEndDateRange.addObjectsFromArray(tempStartEndDateArray as [AnyObject])
GroupObjectArray(temp)
tempStartEndDateArray.removeAllObjects()
}
i = i+1
}
}
else
{
GroupObjectArray(event as! Event)
}
}
if (result.count>0)
{
if (result.count>=10)
{
self.lastMemorisedDate = (result[(result.count-1)] as! Event).eventEndDate
}
else
{
self.lastMemorisedDate = nil
}
}
ShortArrayByDate()
}
func CreateTemporaryObject(event:Event) ->Event
{
let 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.eventDescription=event.eventDescription
temp.shortURLString=event.shortURLString
return temp
}
func ShortArrayByDate() ->Void
{
let sortDescriptor: NSSortDescriptor = NSSortDescriptor(key: "eventStartDate", ascending: true)
let sortDescriptors = [sortDescriptor]
let sortedArray:NSArray = eventHiddenArray.sortedArrayUsingDescriptors(sortDescriptors)
eventHiddenArray = sortedArray.mutableCopy() as! NSMutableArray
if (self.lastMemorisedDate != nil)
{
let pred = NSPredicate(format: "eventStartDate =< %@", lastMemorisedDate!)
let displayArray:NSArray = eventHiddenArray.filter { pred.evaluateWithObject([=10=]) } ;
eventDisplayArray = displayArray.mutableCopy() as! NSMutableArray
}
else
{
self.eventDisplayArray = sortedArray.mutableCopy() as! NSMutableArray
}
}
func GroupObjectArray(event:Event)->Void
{
self.eventHiddenArray.addObject(event)
}
func GetFirstSlotEventStartEndDate(eventStartDateEndDateArray:NSMutableArray )->NSMutableArray
{
let tempStartEndDateArray = NSMutableArray();
var i:Int = 0
for fisrtDict in eventStartDateEndDateArray
{
let df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd"
if ((fisrtDict["start"] as! NSDate).isEqualToDate((fisrtDict ["end"] as! NSDate)))
{
tempStartEndDateArray.addObject(fisrtDict)
var currentDate: NSDate = fisrtDict["start"] as! NSDate;
let calendar: NSCalendar = NSCalendar.currentCalendar()
let dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:(fisrtDict["start"] as! NSDate), options:NSCalendarOptions(rawValue: 0))!
if (i+1>=eventStartDateEndDateArray.count)
{
break
}
else
{
let secondDict:NSMutableDictionary = eventStartDateEndDateArray[i+1] as! NSMutableDictionary;
if (currentDate.isEqualToDate(secondDict ["start"] as! NSDate))
{
break
}
}
}
else if((fisrtDict["end"] as! NSDate).timeIntervalSinceDate(fisrtDict["start"] as! NSDate) > 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
{
let df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd"
if ((fisrtDict["start"] as! NSDate).isEqualToDate((fisrtDict ["end"] as! NSDate)))
{
var currentDate: NSDate = fisrtDict["start"] as! NSDate;
let calendar: NSCalendar = NSCalendar.currentCalendar()
let dayComponent:NSDateComponents = NSDateComponents()
dayComponent.day = 1;
currentDate = calendar.dateByAddingComponents(dayComponent, toDate:(fisrtDict["start"] as! NSDate), options:NSCalendarOptions(rawValue: 0))!;
if (i+1>=eventStartDateEndDateArray.count)
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"] as! NSDate)
break;
}
else
{
let secondDict:NSMutableDictionary = eventStartDateEndDateArray[i+1] as! NSMutableDictionary;
if (currentDate.isEqualToDate(secondDict["start"] as! NSDate))
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"] as! NSDate)
break;
}
}
}
else if((fisrtDict["end"] as! NSDate).timeIntervalSinceDate(fisrtDict["start"] as! NSDate) > 0 )
{
firstSlotEventEndDate = df.stringFromDate(fisrtDict["end"] as! NSDate);
break;
}
i = i+1
}
return firstSlotEventEndDate;
}
}