title: How to bundle a realm file with my app in swift4.2?
body: <p>I want to show persistent data when on the app first lunch on the device so the user can see it and I use realm as my database.</p>
  
  <p>I was deceived after I filled my file with data on the simulator and now need to merge or to bundle the data file with my app.
  Now I copied my default.realm file to dcouments then
  I copied some related codes from stackoverflow in AppDelegate to bundle it but failed !</p>
  
  <pre><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
      // Override point for customization after application launch.
      openRealm() //2
      print(Realm.Configuration.defaultConfiguration.fileURL) //3
      return true
  }
  
  //1
  func openRealm() {
      let bundlePath = Bundle.main.path(forResource: "default", ofType: "realm")!
      let defaultPath = Realm.Configuration.defaultConfiguration.fileURL!.path
      let fileManager = FileManager.default
  
      // Only need to copy the prepopulated `.realm` file if it doesn't exist yet
      if !fileManager.fileExists(atPath: defaultPath){
          print("use pre-populated database")
          do {
              try fileManager.copyItem(atPath: bundlePath, toPath: defaultPath)
              print("Copied")
          } catch {
              print(error)
          }
      }
  
  } //f
  </code></pre>
  
  <p>when I build the app always crashes and Xcode telling me that value is nill</p>
  
  <blockquote>
    <p>Thread 1: Fatal error: Unexpectedly found nil while unwrapping an
    Optional value</p>
  </blockquote>