Comment faire de cet appel de code en nuage pars.com?
-
21-12-2019 - |
Question
Remarque:
Voici quelques réflexions de CA à l'analyse de ceci:
https://www.parse .com / questions / iOS-quand-swift-for-parse-be-prête
(Notez à quel point cette question est populaire - sujet brûlant). J'espère que cela aide quelqu'un
Voici un appel de code de panneaux IOS7 ...
Comment faire cela à Swift? acclamations
Pour être clair ... Pouvez-vous utiliser "CallFunctionInfrackground" à Swift , ou devez-vous simplement appeler à une classe Objc?
-(void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
int thisRow = indexPath.row;
PFUser *delFriend = [self.theFriends objectAtIndex:thisRow];
NSLog(@"you wish to delete .. %@", [delFriend fullName] );
// note, this cloud call is happily is set and forget
// there's no return either way. life's like that sometimes
[PFCloud callFunctionInBackground:@"clientRequestFriendRemove"
withParameters:@{
@"removeThisFriendId":delFriend.objectId
}
block:^(NSString *serverResult, NSError *error)
{
if (!error)
{
NSLog(@"ok, Return (string) %@", serverResult);
}
}];
[self back]; // that simple
}
Remarque, j'ai remarqué qu'il s'agit d'une page d'atterrissage Google pour tenter de déterminer "comment les appels de code en nuage" (sans rapport avec SWIFT). Voici un ensemble complet complet de
La solution
Ajouter un fichier objectif-c .m à votre projet.XCode vous posera de la création d'un fichier d'en-tête de pont.Dites oui.
Supprimer le fichier .m.Dans le fichier d'en-tête de pont, ajoutez votre relevé d'importation:
#import <Parse/Parse.h>
Une autre réponse, qui a une excellente pas à pas à pas que le mien: https://stackoverflow.com/a/24005242/3539884/a>
Maintenant, vous pouvez appeler le code d'analyse natal à Swift, c'est-à-dire.:
import UIKit
import Foundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
Parse.setApplicationId("appid", clientKey: "clientkey")
var obj = PFObject(className:"TestObject")
obj.setObject("bar", forKey: "foo")
obj.saveInBackgroundWithBlock ({
(succeeded: Bool!, err: NSError!) -> Void in
NSLog("Hi")
})
}
}
Autres conseils
Il n'est pas possible d'appeler cette fonction exacte ( CallFunctionIncunclackbackground ) car il s'agit d'une fonction Obj-C.
Veuillez vous référer à Cette question Comment appeler obj-c fonctions.
avec l'analyse de temps introduira également la mise en œuvre rapide.