title: How to write JSON to Realm in Swift
body: <p>I can't find information how to write my <code>JSON</code> data to my <code>Realm DB</code> in <code>Swift</code>. </p>
  
  <p>I have class: </p>
  
  <pre><code>class News: Object {
      dynamic var newsID: String = ""
      dynamic var newsTitle: String = ""
      dynamic var newsFullText: String = ""
      dynamic var newsAutor: String = ""
      dynamic var newsCommentCount: String = ""
      dynamic var newsSeenCount: String = ""
      dynamic var newsDate: String = ""
      dynamic var newsCategory: String = ""
  }
  </code></pre>
  
  <p>In here I take <code>JSON</code> from server:</p>
  
  <pre><code>func parseJSONData(data: NSData) -&gt; [News] {
  
      do {
          let temp: NSString = NSString(data: data, encoding: NSUTF8StringEncoding)!
          let myNSData = temp.dataUsingEncoding(NSUTF8StringEncoding)!
  
          let jsonResult = try NSJSONSerialization.JSONObjectWithData(myNSData, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
          let jsonNews = jsonResult["posts"] as! [AnyObject]
          for jsonnewes in jsonNews {
              let newsJson = News()
              newsJson.newsTitle = jsonnewes["post_title"] as! String
              newsJson.newsAutor = jsonnewes["author_name"] as! String
              newsJson.newsFullText = jsonnewes["full_text"] as! String
              newsJson.newsID = jsonnewes["id"] as! String
              newsJson.newsCategory = jsonnewes["menu_category_name"] as! String
              newsJson.newsDate = jsonnewes["create_date"] as! String
              newsJson.newsSeenCount = jsonnewes["review"] as! String
              newsJson.newsCommentCount = jsonnewes["comment_count"] as! String
              newsItems.append(newsJson)
          }
      } catch {
          print(error)
      }
      return newsItems
  }
  </code></pre>
  
  <p>And how to write my data to <code>Realm DB</code>? </p>