# Core data problem swift

**URL:** <https://forums.kodeco.com/t/core-data-problem-swift/27702>\
**Category:** Swift\
**Created:** [March 30, 2017, 4:01pm UTC](https://forums.kodeco.com/t/core-data-problem-swift/27702 "2017-03-30T16:01:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![excell99](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/excell99/32/81494_2.png) [@excell99](https://forums.kodeco.com/u/excell99)\
**Post date:** [March 30, 2017, 4:01pm UTC](https://forums.kodeco.com/t/core-data-problem-swift/27702/1 "2017-03-30T16:01:13Z")

</div>

Hi All

I have a strange problem that i can nail down

When i run the function below for the first time to collect data from core data it works fine  
but when i call it a second time it return an empty array

the point being it works fine one but only once, i can assure you i call with the same params etc

I don’t know if the code below will be enough info but we will see

thanks in advance  
func getQuestions(set : Int16)-\>[Questions]{

```
    var questions = [Questions]()
    let fetchRequest : NSFetchRequest<Questions> = Questions.fetchRequest()
    // select the questions with the matching parametewrs
    let predicate = NSPredicate(format : "set = %@" , String(set))
    fetchRequest.predicate = predicate

    do {
        
        questions = try context.fetch(fetchRequest)
        print(questions.count)
        if questions.count > 0 {
            
            // MARK: Bug Fix
            // fix bug to prevent current answer retaining a change when
            // a new project is created...
            // someware questions array in not getting reset and i can't find it
            //
            for index in 0...questions.count - 1 {
                
                questions[index].currentAnswer = 0
            }
            
            return questions
        }
    } catch {
        
        let error = error as NSError
        print("QuestionMethods: getQuestions \(error)")
    }
    
    return questions
}

```
