ios


Can't seem to get Parse includeKey working


I have a mongoDB with tables of the default "_User" and a custom "posts" tables.
_User table contains: _id, username, fullname ...
posts table contains: _id, userid, title, pic ... // Where userid = _User._id
I need to be able to grab the "_user.fullname" for each pic in "posts" in a single findObjectsInBackgroundWithBlock.
import UIKit
import Parse
class ViewController: UIViewController {
// UI Objects
#IBOutlet weak var emailTxt: UITextField!
#IBOutlet weak var logInBtn: UIButton!
// Array(s) to hold server data
var fullnameArray = [String]()
var followArray = ["ItGwBmpMKi", "4LwW0oapds", "lIqEtv26Vx"]// _id from _User table
var postsusersFN = ""
// Page size
var page : Int = 10 // Later to be set in user settings
override func viewDidLoad() {
super.viewDidLoad()
print("Start Test")
}
#IBAction func logIn_clicked(sender: AnyObject) {
let query = PFQuery(className: "posts")
query.whereKey("userid", containedIn: self.followArray)
query.includeKey("User.fullname")
//query.includeKey("_user.fullname")
//query.includeKey("userid")
//query.includeKey("ObjectId")
query.limit = self.page
query.addDescendingOrder("createdAt")
query.findObjectsInBackgroundWithBlock({ (objects:[PFObject]?, error:NSError?) -> Void in
for object in objects! {
if let userFN = object["userid"] as? PFObject {
self.postsusersFN = userFN["fullname"] as! String!
print("Fullname for post: \(self.postsusersFN)")
}
print("*********")
print(object)
}
})
}
}
My output is as follows:
Start Test
*********
<posts: 0x1740a1740, objectId: mvncM8aItr, localId: (null)> {
pic = "<PFFile: 0x17404bc10>";
title = "(9) Some Title";
userid = lIqEtv26Vx;
uuid = "lIqEtv26Vx C44F2A48-D343-4C0A-AFCC-44FC23D0FAA8";
}
ANY insight/direction would be appreciated
ALMOST have this working, can I get a little help over the last hurdle?
I am now getting the fullname but can't figure out how to align the userid index with the (users)fullname index. It is returned random on each test build.
Is it time to get away from Parse and do a complete rewrite as this may be my last hurdle of issues for my project?
NEW CODE:
import UIKit
import Parse
class ViewController: UIViewController {
// UI Objects
#IBOutlet weak var emailTxt: UITextField!
#IBOutlet weak var logInBtn: UIButton!
// Arrays to hold server data
var postArray = [String]()
var useridArray = [String]()
var avaArray = [PFFile]()
var dateArray = [NSDate?]()
var picArray = [PFFile]()
var titleArray = [String]()
var uuidArray = [String]()
var fullnameArray = [String]()
var followArray = ["4LwW0oapds","lIqEtv26Vx","ItGwBmpMKi"]
// Page size
var page : Int = 10
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func logIn_clicked(sender: AnyObject) {
let query = PFQuery(className: "posts")
query.whereKey("userid", containedIn: self.followArray)
query.limit = self.page
query.addDescendingOrder("title")
findAsync(query).continueWithSuccessBlock { (task: BFTask!) -> BFTask in
let objects = task.result! as! NSArray
for object in objects {
self.useridArray.append(object.objectForKey("userid") as! String)
self.dateArray.append(object.createdAt)
self.picArray.append(object.objectForKey("pic") as! PFFile)
self.titleArray.append(object.objectForKey("title") as! String)
self.uuidArray.append(object.objectForKey("uuid") as! String)
}
return self.findAsync(query)
}.continueWithSuccessBlock { (task: BFTask!) -> BFTask in
self.fullnameArray.removeAll(keepCapacity: false)
for(index,user) in users.enumerate() {
let subQuery = PFQuery(className: "_User")
subQuery.whereKey("objectId", equalTo: user)
subQuery.getFirstObjectInBackgroundWithBlock {
(subobject: PFObject?, error: NSError?) -> Void in
if error != nil || subobject == nil {
print(error)
} else {
let fullName = subobject!.valueForKey("fullname") as! String
self.fullnameArray.insert(fullName, atIndex: index)
}
}
}
return self.findAsync(query)
}.continueWithSuccessBlock { (task: BFTask!) -> AnyObject! in
// Complete
return nil
}
}
func findAsync(query:PFQuery) -> BFTask {
let task = BFTaskCompletionSource()
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil {
task.setResult(objects)
} else {
task.setError(error!)
}
}
return task.task
}
}

Related Links

How do I set bold font on UILabel in iOS?
Realm Browser not allowing me to open files
Master-detail segue from DetailViewController with back button
Change date format using NSDateFormatter
How passing data with multiple prepareforsegue in a uitableviewcell swift
UITextViewDelegate in non viewcontroller class
How can I get indexPath of a uiview on a cell - iOS
How to allow audio to continue to play when app is backgrounded?
How to limit the pulling distance with a refresh control?
Image fits into UICollectionView Cell
Caching the downloaded data
Core Location and Google Maps
(Objective C) NSDate is nil to convert a date in String
Swift need to reload TableView that is contained within a containerView
Remove iAds from SKScene
Adjust UICollectionView Size Dynamically to Ensure No Inter Item Spacing

Categories

HOME
uwp
openshift-origin
graylog2
prebuild
image-segmentation
xamarin.forms-listview
cql3
feed
intel-xdk
wikipedia-api
sony-camera-api
partitioning
raspberry-pi2
jmespath
drupal-commerce
curve-fitting
pydev
multiprocessing
datamatrix
missingmethodexception
dsc
padding
rrd
text-parsing
paket
asp.net-identity-2
apscheduler
jsplumb
html-select
docker-image
packaging
transpose
mindstorms
free-diameter
pulseaudio
gulp-babel
docker-swarm-mode
sections
mashery
derbyjs
manual
flying-saucer
untagged
itertools
vispy
logstash-jdbc
ispconfig
measurement-protocol
xceed
flattr
mit-scheme
coldfusion-11
cglib
android-location
xmllint
network-traffic
namenode
winobjc
pypyodbc
jni4net
document-ready
materialdrawer
sejda
python-2.3
spymemcached
hypervisor
cocoon-gem
julian
chunk-templates
xsb
swift-array
modern-ui
applicationstate
nolio
jet.com-apis
iqueryable
linguistics
syndication-feed
controlsfx
master-theorem
fig
hobbitmon
mydbr
yourls
notifyicon
fay
nsimageview
capitalize
adlds
loadlibrary
hamlc
memento
calloc
ad-hoc-distribution
graphiti-js
hpple
proxy-classes
livevalidation
postgresql-8.1
ssao
treetop
paredit
.net-1.1
renderaction
indextank
arraycopy
stsadm
templatebinding

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App