Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

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

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
         

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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  =

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...