I got that error a while ago and I'm not sure, what's wrong. The Post is just normal custom class with two attributes of type String and int.
web api :http://jsonplaceholder.typicode.com/posts
PostService :
class PostService {
var settings:Settings!
init(){
self.settings = Settings()
}
func getPosts(callback:(NSArray) ->()){
request(settings.viewPost, callback: callback)
}
func request(url:String , callback:(NSArray) ->() ){
let nsURL = NSURL(string: url)
let task = NSURLSession.sharedSession().dataTaskWithURL(nsURL!){(data , repsonse , error) in
//var error:NSError?
do {
let response = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as! NSArray
callback(response)
} catch {
print(error)
}
}
task.resume()
}
}
settings :
import Foundation
class Settings {
var viewPost = "http://jsonplaceholder.typicode.com/posts"
}
post:
class Post {
var _userId:Int
var _title: String
init(userid:Int , title:String){
self._userId = userid
self._title = title
}
func toJSON() ->String{
return ""
}
}
and tableViewController:
class TableViewController: UITableViewController {
var postsCollection = [Post]()
var service:PostService!
override func viewDidLoad() {
super.viewDidLoad()
service = PostService()
service.getPosts{
(response) in
self.loadPosts(response[" "] as! NSArray )
}
}
func loadPosts(posts:NSArray){
for post in posts{
var userId = post["userId"] as! Int
var title = post["title"] as! String
let postObj = Post(userid: userId, title: title)
postsCollection.append(postObj)
dispatch_async(dispatch_get_main_queue()){
self.tableView.reloadData()
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return postsCollection.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let post = postsCollection[indexPath.row] as NSData
cell.textLabel?.text = post._userId
cell.detailTextLabel = post._title
return cell
}
why error Cannot subscript a value of type '[Post]' in line
I'm not sure that this is the issue but it is an issue.
Since postsCollection has a distinct type there is no need to cast the type.
NSData is the wrong type anyway.
let post = postsCollection[indexPath.row] // the compiler infers to Post
Side note: Put the dispatch block to reload the table view after the repeat loop to create the Post instances. Reloading the table view in each iteration of the loop is very expensive and not necessary.
for post in posts {
...
}
dispatch_async(dispatch_get_main_queue()){
self.tableView.reloadData()
}
And (public) properties starting with a underscore are pretty unusual (in Swift).
PS: There are two further issues
cell.textLabel?.text = String(post._userId)
cell.detailTextLabel?.text = post._title
Edit: Simple working solution, there are only two classes
class Post
class Post : CustomStringConvertible {
var userId:Int
var title: String
init(userid:Int , title:String){
self.userId = userid
self.title = title
}
var description : String { return String(userId) }
}
class TableViewController
class TableViewController: UITableViewController {
var postsCollection = [Post]()
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: "http://jsonplaceholder.typicode.com/posts")
NSURLSession.sharedSession().dataTaskWithURL(url!){ [unowned self] (data , repsonse , error) in
if error != nil {
print(error!)
} else {
do {
let posts = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers) as! [[String:AnyObject]]
for post in posts {
let postObj = Post(userid: post["userId"] as! Int, title: post["title"] as! String)
self.postsCollection.append(postObj)
}
dispatch_async(dispatch_get_main_queue()){
self.tableView.reloadData()
}
} catch let error as NSError {
print(error)
}
}
}.resume()
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 }
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return postsCollection.count }
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let post = postsCollection[indexPath.row]
cell.textLabel!.text = String(post.userId)
cell.detailTextLabel!.text = post.title
return cell
}
}
Related
I am fetching json data from API and filling a UITableview from it - up to here everything is working fine.
The issue is saving the data into core data. As far as I know - I am saving the data correctly, and I have debugged to see that actually 15 objects have been saved into the core data. my issue is when trying to retrieve the data back from core data - I am getting only one object from the entire json list, usually it is the first one but sometimes it is some other index.
here is my VC:
import UIKit
import CoreData
import Kingfisher
class MoviesViewController: UITableViewController {
let base_url = "https://api.androidhive.info/json/movies.json"
let context = PersistanceService.context
var moviesArray = [Movie]()
override func viewDidLoad() {
super.viewDidLoad()
if loadData(){
print("loading items from local presistancy")
} else {
print("fetching new data from api")
dataFetchFromMoviesApi()
}
//dataFetchFromMoviesApi()
tableView.estimatedRowHeight = 180
tableView.register(UINib(nibName: "TableViewCell", bundle: nil), forCellReuseIdentifier: "MovieCell")
}
//MARK: - TableView Delegate Method
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
performSegue(withIdentifier: "showMovieDetails", sender: moviesArray[indexPath.row])
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
//MARK: - TableView Datasource Methods
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let movie = moviesArray[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "MovieCell", for: indexPath) as! TableViewCell
cell.title.text = "Title: \(movie.title)"
cell.rating.text = "Rating: \(String(movie.rating))"
cell.releaseYear.text = "Release Year: \(String(movie.releaseYear))"
cell.genre.text = "Genre: \(String(movie.genre[0]))"
cell.movieImage.downloaded(from: movie.image)
return cell
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return moviesArray.count
}
//MARK: - Segue Method
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showMovieDetails" {
let movieVC = segue.destination as! MovieDetailsViewController
movieVC.selectedMovie = sender as? Movie
}
}
//MARK: - Data Fetching Method
func dataFetchFromMoviesApi(){
httpRequest(urlForRequest: base_url) { [weak self] (data: Data?, error: Error?) in
if error == nil { //no error - continue
if let moviesData = data { //un-wrapping the data object
let decoder = JSONDecoder()
do {
let responseArray = try decoder.decode([Movie].self, from: moviesData)
//print(responseArray)
DispatchQueue.main.async {
self?.moviesArray = responseArray
self?.moviesArray.sort(by: {$0.releaseYear > $1.releaseYear})
for movie in self!.moviesArray {
let movieModel = MovieModel(context: self!.context)
movieModel.title = movie.title
movieModel.releaseYear = String(movie.releaseYear)
movieModel.rating = String(movie.rating)
movieModel.genre = movie.genre[0]
movieModel.image = movie.image
}
PersistanceService.saveContext()
self?.tableView.reloadData()
}
} catch {
print(error)
}
}
} else {
//error fetching data
print(error?.localizedDescription ?? "error with no description")
}
}
}
//MARK: - Http Request
private func httpRequest(urlForRequest: String, completion: #escaping (Data?, Error?) -> Void){
guard let url = URL(string: urlForRequest) else {return}
let task = URLSession.shared.dataTask(with: url) { (data: Data?, urlResponse: URLResponse?, error: Error?) in
if error == nil {
//task was succfull
completion(data, nil)
} else {
//task was unsuccessfull
completion(nil, error)
}
}
task.resume()
}
func saveData(){
do {
try context.save()
} catch {
print("error saving context, \(error.localizedDescription)")
}
}
func loadData() ->Bool{
let fetchRequest: NSFetchRequest<MovieModel> = MovieModel.fetchRequest()
do {
let movies = try PersistanceService.context.fetch(fetchRequest)
print(movies.count)
for movie in movies {
let title = movie.title!
let rating = Float(movie.rating!)!
let image = movie.image!
let genre = [movie.genre!]
let releaseYear = Int(movie.releaseYear!)!
let newMovie = Movie(title: title, image: image, rating: rating, releaseYear: releaseYear, genre: genre)
self.moviesArray.append(newMovie)
print("movies array count: \(moviesArray.count)")
print("successfully loaded items")
return true
}
} catch {
print("error fetching from core data, \(error)")
return false
}
return false
}
}
I am working with 2 parallel data type - one is a movie entity for core data, the other is a movie struct that conforms to the codeable protocol in other to decode json. so when getting back the fetch request I assign it into the movies object, and to my understanding that makes the movies object as an array of my movies entity. Am I right?
Hopefully someone could point me of the mistake I am doing.
You have placed your return in the wrong place in loadData, move it out of the for loop
for movie in movies {
let title = movie.title!
let rating = Float(movie.rating!)!
let image = movie.image!
let genre = [movie.genre!]
let releaseYear = Int(movie.releaseYear!)!
let newMovie = Movie(title: title, image: image, rating: rating, releaseYear: releaseYear, genre: genre)
self.moviesArray.append(newMovie)
print("movies array count: \(moviesArray.count)")
print("successfully loaded items")
// return true <-- This was wrong
}
return true //move it here
I'm getting the following error:
Cannot assign value of type '[[String : AnyObject]]' to type '[[String : AnyObject?]]'
It's strange this assignment was working before then when I restarted my Xcode, I started to get this error. From what I have read online, this should not give the error.
Here is my code:
import UIKit
import Alamofire
import SwiftyJSON
class Signal Condo TableViewController: UITableViewController {
#IBOutlet var tableview: UITableView!
var singleCondoData = [[String:AnyObject]]()
var CondoIndivi = [[String:AnyObject]]()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
self.tableView.delegate = self
self.tableView.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return singleCondoData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SignleTableTableViewCell
if singleCondoData.count != 0 {
let dict = singleCondoData[indexPath.row] as NSDictionary
//cell.label1.text? = (dict["name"] as? String)!
if let nullcheck = (dict["address"] as? String) {
cell.label2.text? = nullcheck
}
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let dict = singleCondoData[indexPath.row] as NSDictionary
if let unitNullCheck = (dict["mls_number"] as? String) {
let item_id = unitNullCheck
getCondoUnits(item_id)
print(item_id)
}
}
//get the individual condo id
func getCondoUnits(condo_id : String){
Alamofire.request(.GET, "http://android.goidx.com/search/?mls_number=" + String(condo_id)).validate().responseJSON { response in
if let value = response.result.value {
let json = JSON(value)
if let resData = json.arrayObject {
self.CondoIndivi = (resData as? [[String:AnyObject]])!
print(self.CondoIndivi)
}
if self.CondoIndivi.count > 0 {
self.tableview.reloadData()
}
}
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
switch identifier {
case "details" :
let buildingdDetailVC = segue.destinationViewController as! DetailsViewController
buildingdDetailVC.CondoIndivi2 = self.CondoIndivi // line of the error
default:
break
}
}
}
}
The type of CondoIndivi2 variable is [[String: AnyObject?]] but you are passing an array of type [[String: AnyObject]] where the dictionary values are non-optional.
Since any non-optional value with same type can be safely converted to its optional corresponding, you can do the following:
buildingdDetailVC.CondoIndivi2 = self.CondoIndivi.map { $0 as [String: AnyObject?] }
I m getting this error :fatal error: Index out of range .I can't get what i m doing wrong .What i'm trying to do is , access an array dictionary by using an integer index than pass a string to get the value mapped to it .The sample works fine on playground but not excode why ? (The array dictionary is not empty)
Here is my code
var CondoIndivi2 = [[String:AnyObject]]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
scrollView.contentSize.height = 1500
print(CondoIndivi2)
if let description_Condo = self.CondoIndivi2[0]["description"] as? String {
print(description_Condo)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
This is the view that sends data to CondoIndivi2
import UIKit
import Alamofire
import SwiftyJSON
class SignleCondoTableViewController: UITableViewController {
#IBOutlet var tableview: UITableView!
var singleCondoData = [[String:AnyObject]]()
var CondoIndivi = [[String:AnyObject]]()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
self.tableView.delegate = self
self.tableView.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return singleCondoData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SignleTableTableViewCell
if singleCondoData.count != 0 {
let dict = singleCondoData[indexPath.row] as NSDictionary
//cell.label1.text? = (dict["name"] as? String)!
if let nullcheck = (dict["address"] as? String) {
cell.label2.text? = nullcheck
}
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let dict = singleCondoData[indexPath.row] as NSDictionary
if let unitNullCheck = (dict["mls_number"] as? String) {
let item_id = unitNullCheck
getCondoUnits(item_id)
print(item_id)
}
}
//get the individual condo id
func getCondoUnits(condo_id : String){
Alamofire.request(.GET, "http://android.goidx.com/search/?mls_number=" + String(condo_id)).validate().responseJSON { response in
if let value = response.result.value {
let json = JSON(value)
if let resData = json.arrayObject {
self.CondoIndivi = resData as! [[String:AnyObject]]
print(self.CondoIndivi)
}
if self.CondoIndivi.count > 0 {
self.tableview.reloadData()
}
}
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
switch identifier {
case "details" :
let buildingdDetailVC = segue.destinationViewController as! DetailsViewController
buildingdDetailVC.CondoIndivi2 = self.CondoIndivi
default:
break
}
}
}
/*
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
As #James put in his comment, you're creating an empty array in your code:
var CondoIndivi2 = [[String:AnyObject]]()
And then you're trying to access indexing in the position 0:
if let description_Condo = self.CondoIndivi2[0]["description"] as? String {
print(description_Condo)
}
And of course, you will have a runtime error of Index of out Range because your array it's empty, you always need to be sure before index an array that the index is greater than zero, less than equal to the size of the array and the array is not empty.
I hope this help you.
Inside your getCondoUnits(condo_id : String) is an asynchronous block(Alamofire.request), the CondoIndivi2 is received later than the viewDidLoad is executed. You should just pass condo_id to next viewController and do the request in it.
The controller has a collectionView, including 1 cell, 5 section and some row, downloading data from LeanCloud just like Parse. Code always fails with fatal error: Array index out of range. In my opinion, I may have some problem in dealing with array of array, about how to access and how to add element. Any one can help me solve this bug? The bug line is listed below:
var temp = self.restaurantLean[number].
import UIKit
import AVOSCloud
class DiscoverViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, RestaurantLeanCollectionCellDelegate, UIGestureRecognizerDelegate {
#IBOutlet var imageView: UIImageView!
#IBOutlet var collectionView: UICollectionView!
private var restaurantLean = [[RestaurantLean]]()
override func viewDidLoad() {
super.viewDidLoad()
collectionView.backgroundColor = UIColor.clearColor()
loadTripsFromLeanCloud()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//MARK: Data Source
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return restaurantLean.count
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return restaurantLean[section].count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! RestaurantLeanCollectionCell
cell.delegate = self
cell.nameLabel.text = restaurantLean[indexPath.section][indexPath.row].name
cell.typeLabel.text = restaurantLean[indexPath.section][indexPath.row].type
cell.locationLabel.text = restaurantLean[indexPath.section][indexPath.row].location
cell.isLike = restaurantLean[indexPath.section][indexPath.row].isLike
cell.imageView.image = UIImage()
cell.layer.cornerRadius = 4.0
if let image = restaurantLean[indexPath.section][indexPath.row].image {
image.getDataInBackgroundWithBlock({ (imageData, error) -> Void in
print(image)
if let data = imageData {
print("loading")
cell.imageView.image = UIImage(data: data)
print("success")
}
})
}
return cell
}
//Download the data from Baas LeanCloud
func loadTripsFromLeanCloud() {
restaurantLean.removeAll(keepCapacity: true)
for number in 0...4 {
let name = "Restaurant_" + String(number)
print(name)
print(number)
let query = AVQuery(className: name)
query.cachePolicy = AVCachePolicy.NetworkElseCache
print("1")
query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
print("2")
if let error = error {
print("3")
print("Error: \(error) \(error.userInfo)")
}
print("4")
if let objects = objects {
print("5")
for (index, object) in objects.enumerate() {
let restaurant = RestaurantLean(avObject: object as! AVObject)
self.restaurantLean[number].append(restaurant)
let indexPath = NSIndexPath(forRow: index, inSection: number)
self.collectionView.insertItemsAtIndexPaths([indexPath])
}
}
})
print("6")
}
}
You are not adding elements to restaurantLean array itself (you only add objects to nested arrays). Here is possible solution.
func loadTripsFromLeanCloud() {
restaurantLean.removeAll(keepCapacity: true)
for number in 0...4 {
restaurantLean.append([]) // This line
// ...
}
}
I have to put data in tableview, but even tough I get info from JSON, I can't pass data to postTitle variable. Why is that? Here is my code:
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var postTitle = [AnyObject]()
override func viewDidLoad() {
super.viewDidLoad()
var baseURL = "https://hacker-news.firebaseio.com/v0/topstories.json"
// https://hacker-news.firebaseio.com/v0/item/9324191.json
if let url = NSURL(string: baseURL) {
var taskURL = NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in
if error != nil {
println("Error: \(error.localizedDescription)")
} else {
var jsonError: NSError?
if let topStories = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonError) as? NSArray {
self.postTitle.append(topStories)
}
}
})
taskURL.resume()
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
println(postTitle.count)
return postTitle.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = UITableViewCell()
println(self.postTitle)
// cell.textLabel?.text = postTitle[indexPath.row]
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
topStories is an NSArray, but you are appending it to the postTitle array (which is of type [AnyObject]). Array.append adds a single item to the array. So you will have added one entry, an NSArray of a bunch of post IDs, to your postTitle array.
I am guessing what you want is to add the contents of topStories to postTitle? In which case you want to use the extend rather than the append method:
self.postTitle.extend(topStories)
Given that you apparently reload ALL the titles with each request, you could just as easily do this: self.titles = topStories
I just built a test app this way and it worked perfectly fine.
PS: self.postTitle.append would have yielded the wrong result anyway, as it would also append titles you already have in your array. The method you probably should be using would be self.postTitle.join as it uses intersection.
So the other guy from Reddit help me out. I was missing few things. First was data type Int, which needs to be passed to instance variable, and second was UITableView: here is working solution. Hope this will help someone.
import UIKit
class ViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {
var postTitles = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
var baseURL = "https://hacker-news.firebaseio.com/v0/topstories.json"
if let url = NSURL(string: baseURL) {
var taskURL = NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in
if error != nil {
println("Error: \(error.localizedDescription)")
} else {
var jsonError: NSError?
if let topStories = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &jsonError) as? [Int] {
self.postTitles = Array(topStories[0...9])
// Reload the table with our new results!
self.tableView.reloadData()
}
}
})
taskURL.resume()
}
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return postTitles.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
let postTitle = String(self.postTitles[indexPath.row])
cell.textLabel?.text = postTitle
return cell
}
}