an internal error occurred . Source editor functionality is limited . Attempting to restore

ぐ巨炮叔叔 提交于 2019-12-25 09:02:11

问题


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...


回答1:


after step by step reviewing of my code finally i figured out issues in my code. If you have more syntax mistakes in your code the swift 2.x Xcode compile stops showing the syntax mistakes & gives the error an internal error occurred . Source editor functionality is limited . Attempting to restore...

The corrected formatting of code is -

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($0) } ;
                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;
}

}


来源:https://stackoverflow.com/questions/37805017/an-internal-error-occurred-source-editor-functionality-is-limited-attempting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!