Pfobject' Does Not Have a Member Named 'Subscript'

PFObject' does not have a member named 'subscript'

This is happening due to the 1.6.4 version of the parse sdk which added Objective-C Nullability Annotations to the framework. In particular the file Parse/PFObject.h defines:

- (PF_NULLABLE_S id)objectForKeyedSubscript:(NSString *)key;

which is causing the Swift compile error. Removing the PF_NULLABLE_S fixes the problem.

On the other hand it seems correct that an object for a keyed subscript might be nil, so I suspect this is a Swift bug...

PFObject does not have a member named 'subscript'

Try:

let messageText:String? = messageObject.valueForKey("Text") as? String

Error with Parse: PFObject does not have a member named 'createdAt'

I figured out how to get the property, thanks to @SanitLee answer. I post my code with the solution so that everybody could see it.

Solution

In my function named loadCheckInData() I added for object in objects { to the findObjectsInBackgroundWithBlock method. See below:

func loadCheckInData() {

var query = PFQuery(className: "CheckIn")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock({
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {

// Do something
if let objects = objects as? [PFObject] {
for object in objects { // <--- Added
// data stored in the var named "CheckedPatient"
self.CheckedPatients = Array(objects.generate())
}
}
} else {
// ...
}
})
}

Then to retrieve the createdAt property inside the cellForItemAtIndexPath function, I changed:

if let value = CheckedPatients[indexPath.row]["createdAt"] as? String {
cell.cellDay.text = value
}

into:

    var DateVar : PFObject = CheckedPatients[indexPath.row]
var dateFormatter:NSDateFormatter = NSDateFormatter() // Formating
dateFormatter.dateFormat = "EEEE dd MMM HH:mm"
cell.cellDay.text = dateFormatter.stringFromDate(DateVar.createdAt!)

Now it works as I want. If you have any advice, thorough explanations or improvement about the code, feel free to modify and explain it.

Thanks

PFUser does not have a member named subscript?

You can use the method setValue:forKey:

Example:

func signUp() {
var user = PFUser()
user.email = email.text
user.setValue(firstName.text, forKey:"firstName")
user.setValue(zipcode.text, forKey:"zipcode")
user.objectId = objectId
//etc... }

PFUser' does not have a member named 'subscript'

Ok I got it!

        user.setValue(imageFile, forKey:"photo")

it works now!!

PFObject does not have a member named 'saveInBackground' in Xcode 6.0.1, Yosemite GM3

The saveInBackground method is declared in the header to return a BFTask * object, which is part of the Bolts framework. Make sure your project is linking the Bolts framework, and then add

#import <Bolts/Bolts.h>

to your bridging header.

This solved a few "missing" APIs in Swift for me (this one, as well as PFAnalytics.trackAppOpenedWithLaunchOptions mentioned here: Why does my PFAnalytics not have trackAppOpeneWithLaunchOptions function? (IOS SWIFT)

Swift& Parse.com Adding values from a table into an array error not having a member named subscript

In Swift 2.0, findObjects returns optional array of PFObject instead of optional AnyObject. Try this

override func viewDidLoad() {
super.viewDidLoad()

var taskQuery = PFQuery(className: "Assesment")

taskQuery.findObjectsInBackgroundWithBlock {
(success:[PFObject]?, error: NSError?) -> Void in

if let objects = success {
for object in objects {
taskMgr.addtask(object["name"], (object["send"] == "true"))
//taskMgr.addtask(object["name"], (object["send"].isEqual("true")))
}
}
}
}


Related Topics



Leave a reply



Submit