title: large JSON file Swift
body: <p>I'm making a golf app written in Swift. Inside of my app I have a search bar where a user can search for a golf course. I have a large JSON file in Xcode containing a large golf course data base. I parse this JSON data base to give me the name and location of the golf courses and then display them as the user is searching in the search bar. The problem is the JSON file is 17MB and has roughly 18,000 golf courses, which is making the parsing process long and the golf course names don't start populating when the user starts typing into the search bar until about 6 seconds in.</p>
  
  <p>I currently have a DataManager Class which goes and grabs my JSON file. I'm using SwiftyJSON to help parse the data and then append that data to an array so I can display it in my search bar's table view.</p>
  
  <p>Any suggestions on how to speed up the process of parsing such a large file or reducing the file size??</p>
  
  <p>Thanks in advance!</p>
  
  <p>-Code for my data manager and my function that parses my JSON file:</p>
  
  <p>DataManager: </p>
  
  <pre><code> class DataManager {
  
     class func getGolfCoursesFromFileWithSuccess(success: ((data: NSData) -&gt; Void)) {
  
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
  
    let filePath = NSBundle.mainBundle().pathForResource("golfCourseData",ofType:"json")
  
    var readError:NSError?
    do {
      let data = try NSData(contentsOfFile:filePath!,
        options: NSDataReadingOptions.DataReadingUncached)
      success(data: data)
      } catch let error as NSError {
      readError = error
      print(readError)
       } catch {
        fatalError()
       }
     })
    }
   }
  </code></pre>
  
  <p>Function to Parse JSON (called in viewDidLoad):</p>
  
  <pre><code> func loadCoursesFromJSONFile() {
      DataManager.getGolfCoursesFromFileWithSuccess { (data) -&gt; Void in
          let json = JSON(data: data)
  
          if let courseArray = json.array {
  
              for course in courseArray {
  
                  let golfCourseName: String? = course["biz_name"].string
  
                  if golfCourseName != nil {
                      let golfCourse = GolfCourse(className: "PreviousCourse")
                      golfCourse.courseName = golfCourseName!
                      self.golfCourseCollection.append(golfCourse)
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Example of the JSON:</p>
  
  <p>-I only need "biz_name", "e_city", "e_state"</p>
  
  <pre><code>{
       "id":18634,
  "biz_name":"Twin Lakes Golf Course",
  "e_address":"6100 Clifton Rd",
  "e_city":"Clifton",
  "e_state":"VA",
  "e_postal":"20124",
  "e_zip_full":"",
  "e_country":"USA",
  "loc_county":"Fairfax",
  "loc_area_code":703,
  "loc_FIPS":51059,
  "loc_MSA":null,
  "loc_PMSA":8840,
  "loc_TZ":"EST",
  "loc_DST":"Y",
  "loc_LAT_centroid":"38.7803",
  "loc_LAT_poly":38.819444,
  "loc_LONG_centroid":-77.3913,
  "loc_LONG_poly":-77.402822,
  "biz_phone":"(703) 631-9372",
  "metal_spikes":"U",
  "play_five":"U",
  "c_holes":"18",
  "c_type":"Public",
  "year_built":"",
  "c_designer":"",
  "c_season":"",
  "guest_policy":"",
  "dress_code":"",
  "green_fees":"",
  "weekend_rates":"$26 wknd",
  "adv_tee":"7 days",
  "FIELD33":""
  </code></pre>
  
  <p>},</p>