3

I've imported all the frameworks required but from that point on I don't quite know what to do (I'm new to Swift and no absolutly nothing about Objective C). Parse docs aren't in Swift yet so can someone please provide me with a starting point?

I've initialized my view controller (which doesn't appear when I run the app, I just get a black screen; but based on this video, I should see a table: https://parse.com/tutorials/parse-query-table)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    //Link to Parse
    Parse.setApplicationId("...", clientKey: "...")

    var controller:PFQueryTableViewController = PFQueryTableViewController(className: "test1")
    self.window?.rootViewController = controller
    self.window?.makeKeyAndVisible()

    return true
dom999999
  • 447
  • 1
  • 7
  • 11
  • I know this doesn't answer your question, but Obj C and swift are interoperable. You could for the time being download Parses template projects for Obj C because there are far more tutorials out there for that language. Even if you were able to get your app up and running you may run into errors in the future where tutorials are scarce to guide you through it for swift. You can at anytime convert your [obj c project to swift](http://stackoverflow.com/questions/24002369/how-to-call-objective-c-code-from-swift) at anytime. Since your new to both languages, you have to start ground up either way – soulshined Jan 02 '15 at 04:24

2 Answers2

12

Make sure you have imported all the parse SDK's Create a 2 new cocoa touch class', give one the subclass of PFQueryTableViewController and the other PFTableViewCell. Hook them up in the storyboards. Make sure the Tableview and the cell are pointing to these files. Your Tableview file should look something like this;

import UIKit

class YourTableViewController: PFQueryTableViewController {







// Initialise the PFQueryTable tableview
override init!(style: UITableViewStyle, className: String!) {
    super.init(style: style, className: className)
}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    // Configure the PFQueryTableView
    self.parseClassName = "yourClass"

    self.textKey = "yourObject"
    self.pullToRefreshEnabled = true
    self.paginationEnabled = false
}

// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery! {
    var query = PFQuery(className: "yourClass")
    query.orderByAscending("yourObject")


    return query
}

//override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject) -> PFTableViewCell {

    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as CustomTableViewCell!
    if cell == nil {
        cell = CustomTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
    }

    // Extract values from the PFObject to display in the table cell

    cell.info.text = object["info"] as String


    // Date for cell subtitle
    var dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd"
    let dateForText = object["date"] as NSDate
    cell.date.text = dateFormatter.stringFromDate(dateForText)







    return cell
}

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    // Get the new view controller using [segue destinationViewController].
    var detailScene = segue.destinationViewController as YourDetailViewController

    // Pass the selected object to the destination view controller.
    if let indexPath = self.tableView.indexPathForSelectedRow() {
        let row = Int(indexPath.row)
        detailScene.currentObject = objects[row] as? PFObject
    }
}


Make sure you have set the cells reuse identifier to match what you are setting it to in this code. 

When you I called cell.info, cell.date. These are IBOutlets I have set up in my CustomTableViewCell file.

class CustomTableViewCell: PFTableViewCell {

@IBOutlet weak var info: UILabel!
@IBOutlet weak var date: UILabel!
@IBOutlet weak var mixCoverPhotoImageView: PFImageView!




}
Matt Porter
  • 183
  • 2
  • 12
  • 1
    Make sure in your CustomTableViewCell you also import the necessary Parse libraries like so: import UIKit import Parse import ParseUI – rii Oct 13 '15 at 03:49
  • how do you handle images in your table? i mean how do you set cell.mixcoverphotoimageview property in override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject) -> PFTableViewCell – IamMashed Oct 26 '15 at 18:53
0

i have handle the image with the Alamofireimage-framework. The function is really simple.

Alamofire.request(myURL).responseImage(completionHandler: { (response) in
            if let ThumbImage = response.result.value {
                DispatchQueue.main.async{
                cell?. mixCoverPhotoImageView?.image = ThumbImage
            }
Frank Moos
  • 13
  • 4