Matching a user to a message using Swift and Parse - ios

I'm currently writing a social networking app for iOS using Swift and the Parse SDK. My app is basically a UITableView that displays a timeline of messages from users that sign up for my app. But there is one part that I'm struggling with that I hope the community will be able to help me solve.
My problem is that I want a user to able to tap on a message in my tableview and display the contents of the message and the user that sent it in a UILabel. I pretty much have tried everything I could think of to create this logic but I seem to make things worse. I'm pretty sure a PFquery needs to be used somewhere in this logic. I will attach my source code for my TimelineTableViewController and my custom tableview cell. Full code examples on how to achieve this logic in Swift will be very helpful since I'm already behind.
Thanks in advance
Derek Cacciotti
Twitter: #derekcacciotti
TimelineTableViewController
TableViewCell

In didSelectRowAtIndexPath, use the indexPath to help you figure out which message was tapped like so:
let message: PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
From there, get the values of your message by key (or create a Message class that is a proper PFObject subclass), then use those values to construct a string for your label.

Related

Swift Firebase viewcontroller only for specific user

In my app I have to validate user generated content, to do that I saw that with the panel of Firebase is not a fast thing, so I searched and I found Firebase FireAdmin, but it's not free and what I want is only change a value of approvation from not to yes (after have seeing content).
It's a good idea to make a viewcontroller hide for all exept from me by checking firauth property of Firebase?
let userID : String = (Auth.auth().currentUser?.uid)!
if userID == myid... { show view controller...
Thanx in advance
No it's not a good idea. This value can be changed or the controller can be access if your code is usafe. The application will be heavier for a controller that will not be used by users.
You have to build an admin interface if you don't want to pay for FirebaseAdmin.
In function of what you are looking for, you can also have a look at Firebase Database where you can read and edit values.

do tableView.reloadData() in external class

I am doing a Parse query from an external class. This query give me back the array for populate the tableview, so in the viewDidLoad method I call MyClass.load(array) and the async parse method findObjectInBackground return me the array filled but in the time that the findObject retrive me the objects the tableView is already created and I see an empty tableView, I did a fast google search for the problem and I found that I have to use the self.tableView.reloadData() method, I tried it but I am in an external class and the delegate for the tableView is in the tableViewController, there is any way to refresh the tableView from an external Class?
If you need some code example just ask it, thank you!
EDIT I'm using Swift 2.0
You need to set custom delegate between your external class and ViewControllers.
check for creating custom delegate
Also, you can use NSNotificationCenter for send and post notifications. please check link

Parse CloudCode to remove user from PFRelation

I am new to Parse cloudcode and spinning my wheels to understand JS and write cloudCode to remove user from PFRelation. Can anyone please assist me with parse cloudcode snippet to remove user from PFRelation. I am trying to implement unfriend functionality in the iOS app and I can remove the friend from current users PFRelation and would like to remove current user from the friend PFRelation. I am completely blanked out and don't know how to do that.
I appreciate the help.
Thanks!
The javascript info (that's what you need to do this function on the server) is here: https://parse.com/docs/js_guide#objects-pointers
Specifically, the code on that page that you need is:
var relation = request.user.relation("friends");
relation.remove(other);
request.user.save();
Then you need to get a handle to the other user object and do the same thing there. Are you storing Parse.User objects, or IDs? If it's User objects, the whole code could be this:
var relation = request.user.relation("friends");
var other = relation[0]; // I'm not sure about array indexing though.
var otherRelation = other.relation("friends");
otherRelation.remove(user);
relation.remove(other);
other.save();
request.user.save();
Note that this code isn't really kosher from the perspective of "when the function returns, the logic is done". It's not, since the save is asynchronous. It's faster this way. You could make it both fast and kosher by running both together and waiting for both to finish, but it's been a long time since I've written JavaScript so I can't provide the exact code for that.
Edit: Don't forget to use Parse.Cloud.useMasterKey() to get the right permissions before you try modifying another user.

How to create parse database for simple listing application in iOS

I would like to create database in parse.com for simple application.
where I will have four cells in first view
if I click on any cell, it will go to the next screen and contains some more cells. it goes on like that .
Problem is I have never worked with parse database creation .
can some one help...
database creation is very easy using parse.com. A table is termed as an object in parse. To create a table/object use
PFObject *gameScore = [PFObject objectWithClassName:#"GameScore"];
gameScore[#"score"] = #1337;
gameScore[#"playerName"] = #"Sean Plott";
gameScore[#"cheatMode"] = #NO;
[gameScore saveInBackground];
As this code executes from your Ios app you will see a table "GameScore" with attributes "score", "playerName" and "cheatMode" on your parse data browser.
In the same way you can create different tables.
You can also create a primary(unique) key for each of your table and can link them using those keys.
ios parse.com
Try this Appcoda tutorials
http://www.appcoda.com/ios-programming-app-backend-parse/
and also check parse official site as well
https://parse.com/docs/ios_guide#top/iOS

Display dynamic data in scrollable tableview in Cocos2d

I am making an app in cocos2d. I am using SWTableView library for displaying dynamic contents in tableview in cocos2d. There is absolutely no problem when I am running sample code from SWTableView Example
But when I load my data from server which is dynamic the tableview crashes on scroll.
It allows me to scroll well in the static data just like in the example but I am not able to figure out error as it just gives me BAD_ACCESS.
Note: Possible reason i feel is dynamic data.
If any better method is there to load dynamic data in scrollable way in cocos2d then please suggest.
Thank u.
I just found the solution. There was very strange problem but all working now.
Basically in the sample code (i mentioned in my question) there is a delegate method called
-(SWTableViewCell *)table:(SWTableView *)table cellAtIndex:(NSUInteger)idx;
here idx is NSUInteger but whenever i directly used it without converting it to int or NSInteger it gave BAD_ACCESS command.
Then i stored my data in MutableDictionary and gave it key as its index string
i.e for name data of first person i gave key as "0" (string) and value as name.
Hence whenever i retrieved those values i used
[name objectForKey:[NSString stringWithFormat:#"%d", idx]]
which worked absolutely fine.
Also to mention here the other delegate called
-(NSUInteger)numberOfCellsInTableView:(SWTableView *)table;
returns an integer value, but when i used [Values count] my app used to crash on scroll.
Values is my main array where i store my data received from server.
Finally i started storing my data count in NSUserdefaults and my problem got solved.
Hope this helps somebody.

Resources