[PROJET] - Restkit mapping

Bonjour,



Voici ma première question. J'essaie d'afficher des cartes unitaires qui sont liées à  des cartes composites, on pourrait voir cela comme un auteur qui possède x livres et un livre n'a qu'un auteur.



Donc j'essaie de récupérer tous les livres selon l'id de l'auteur.

Cependant, il me fait une erreur et je ne trouve pas pourquoi, si quelqu'un a la gentillesse de m'accorder du temps...



Voici donc tout mes codes se reportant à  cela:

ViewControllerData.m
<br />
#import &quot;ViewControllerData.h&quot;<br />
#import &quot;Data.h&quot;<br />
#import &quot;CompositeCard.h&quot;<br />
@interface ViewControllerData ()<br />
@end<br />
@implementation ViewControllerData<br />
<br />
- (void)loadTimeline {<br />
    // Charger le modèle via RestKit<br />
    RKObjectManager* objectManager = [RKObjectManager sharedManager];<br />
    objectManager.client.baseURL = [RKURL URLWithString:@&quot;http://localhost:8080/CulturalNetworksMuseumServer/resources&quot;];<br />
    [objectManager loadObjectsAtResourcePath:@&quot;/compositecards/1/artifactcards&quot; delegate:self];<br />
}<br />
<br />
- (void)viewDidLoad<br />
{<br />
    [super viewDidLoad];<br />
   <br />
<br />
    RKLogConfigureByName(&quot;RestKit/Network*&quot;, RKLogLevelTrace);<br />
    RKLogConfigureByName(&quot;RestKit/ObjectMapping&quot;, RKLogLevelTrace);<br />
   <br />
    // Initialisation de RestKit<br />
    RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:@&quot;http://localhost:8080/CulturalNetworksMuseumServer/resources&quot;];<br />
   <br />
    // Active la gestion automatique de l&#39;indicateur de l&#39;activité réseau<br />
    objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;<br />
   <br />
    //Configuration du mappage de l&#39;objet CompositeCard<br />
    RKObjectMapping* compositeMapping = [RKObjectMapping mappingForClass:[CompositeCard class]];<br />
//    [compositeMapping mapKeyPath:@&quot;id&quot; toAttribute:@&quot;cc_id&quot;];<br />
//    [compositeMapping mapKeyPath:@&quot;name&quot; toAttribute:@&quot;cc_name&quot;]; <br />
    [compositeMapping mapAttributes:@&quot;id&quot;, @&quot;name&quot;, nil];<br />
   <br />
    //[[objectManager mappingProvider] setObjectMapping:compositeMapping forKeyPath:@&quot;/compositecards&quot;];<br />
   <br />
    //Configuration du mappage de l&#39;objet Data<br />
    RKObjectMapping * dataMapping = [RKObjectMapping mappingForClass:[Data class]];<br />
    [dataMapping mapKeyPath:@&quot;id&quot; toAttribute:@&quot;ac_id&quot;];<br />
    [dataMapping mapKeyPath:@&quot;file&quot; toAttribute:@&quot;ac_file&quot;];<br />
    [dataMapping mapKeyPath:@&quot;typefile&quot; toAttribute:@&quot;ac_typefile&quot;];<br />
    [dataMapping mapKeyPath:@&quot;author&quot; toAttribute:@&quot;ac_author&quot;];<br />
    [dataMapping mapKeyPath:@&quot;title_topic&quot; toAttribute:@&quot;ac_title_topic&quot;];<br />
    [dataMapping mapKeyPath:@&quot;year&quot; toAttribute:@&quot;ac_year&quot;];<br />
    [dataMapping mapKeyPath:@&quot;technical&quot; toAttribute:@&quot;ac_technical&quot;];<br />
    [dataMapping mapKeyPath:@&quot;support_media&quot; toAttribute:@&quot;ac_support_media&quot;];<br />
    [dataMapping mapKeyPath:@&quot;format&quot; toAttribute:@&quot;ac_format&quot;];<br />
    [dataMapping mapKeyPath:@&quot;owner&quot; toAttribute:@&quot;ac_owner&quot;];<br />
    [dataMapping mapKeyPath:@&quot;collection&quot; toAttribute:@&quot;ac_collection&quot;];<br />
    [dataMapping mapKeyPath:@&quot;descritpion_remarks&quot; toAttribute:@&quot;ac_descritpion_remarks&quot;];<br />
    [dataMapping mapKeyPath:@&quot;compositeCard&quot; toRelationship:@&quot;ac_compositeCard&quot; withMapping:compositeMapping];<br />
   <br />
   <br />
    // Permet de mapper l&#39;objet artifactCard avec la source de ce dernier<br />
    [objectManager.mappingProvider setObjectMapping:dataMapping forResourcePathPattern:@&quot;/compositecards/1/artifactcards&quot;];<br />
    //[[objectManager mappingProvider] addObjectMapping:dataMapping];<br />
   <br />
    NSString * test = @&quot;Mappage dans la View Controller&quot;;<br />
    NSLog(@&quot;%@&quot;,test);<br />
   <br />
   <br />
//    // mise en place d&#39;une TableView<br />
//    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-64) style:UITableViewStylePlain];<br />
//    _tableView.dataSource = self;<br />
//    _tableView.delegate = self;<br />
//    _tableView.backgroundColor = [UIColor clearColor];<br />
//    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;<br />
//    [self.view addSubview:_tableView];<br />
   <br />
    // appel de la fonction qui charge le modèle<br />
    [self loadTimeline];<br />
}<br />
#pragma mark RKObjectLoaderDelegate methods<br />
- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response<br />
{<br />
    NSLog(@&quot;Loaded payload: %@&quot;, [response bodyAsString]);<br />
} <br />
/**<br />
** Permet de charger la liste des adresses provenant des services Rest sous forme de tableau<br />
** Remplir le tableau _addresses (local) avec le tableau d&#39;objects<br />
** Mettre à  jour la TableView<br />
**/<br />
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {<br />
    NSLog(@&quot;Load collection of ArtifactCards: %@&quot;, objects);<br />
    _data = [NSArray arrayWithArray:objects];<br />
    [_tableView reloadData];<br />
}<br />
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {<br />
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@&quot;Error&quot; message:[error localizedDescription] delegate:nil cancelButtonTitle:@&quot;OK&quot; otherButtonTitles:nil];<br />
    [alert show];<br />
    NSLog(@&quot;Hit error: %@&quot;, error);<br />
}<br />
//#pragma mark UITableViewDataSource methods<br />
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {<br />
//    return 1;<br />
//}<br />
//<br />
//- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {<br />
//    return [_data count];<br />
//}<br />
//<br />
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {<br />
//    NSString* reuseIdentifier = @&quot;Data Cell&quot;;<br />
//    UITableViewCell* cell = [_tableView dequeueReusableCellWithIdentifier:reuseIdentifier];<br />
//    if (nil == cell) {<br />
//	    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];<br />
//	    cell.textLabel.numberOfLines = 0;<br />
//	    cell.textLabel.backgroundColor = [UIColor clearColor];<br />
//    }<br />
//    Data *data = [_data objectAtIndex:indexPath.row];<br />
//   <br />
//    //[cell.textLabel setText:[NSString stringWithFormat:@&quot;%@ %@&quot;, address.ad_lat, address.ad_lon]];<br />
//   <br />
//    [cell.textLabel setText:[NSString stringWithFormat:@&quot;%@&quot;, data.ac_title_topic]];<br />
//    [cell.detailTextLabel setText:[NSString stringWithFormat:@&quot;%@&quot;, data.ac_author]];<br />
//   <br />
//    return cell;<br />
//}<br />
<br />
- (void)viewDidUnload<br />
{<br />
    [super viewDidUnload];<br />
    // Release any retained subviews of the main view.<br />
}<br />
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation<br />
{<br />
    return (interfaceOrientation == UIInterfaceOrientationPortrait);<br />
}<br />
@end<br />






ViewControllerData.h
<br />
#import &lt;UIKit/UIKit.h&gt;<br />
@interface ViewControllerData : UIViewController&lt;UIAlertViewDelegate,RKObjectLoaderDelegate&gt;<br />
{<br />
    UITableView* _tableView;<br />
    NSArray* _data;<br />
}<br />
@end<br />






Data.h
<br />
#import &lt;Foundation/Foundation.h&gt;<br />
#import &quot;CompositeCard.h&quot;<br />
@interface Data : NSObject{<br />
NSNumber* _ac_id;<br />
NSString* _ac_file;<br />
NSString* _ac_typefile;<br />
NSString* _ac_author;<br />
NSString* _ac_title_topic;<br />
NSString* _ac_year;<br />
NSString* _ac_technical;<br />
NSString* _ac_support_media;<br />
NSString* _ac_format;<br />
NSString* _ac_owner;<br />
NSString* _ac_collection;<br />
NSString* _ac_descritpion_remarks;<br />
CompositeCard* _ac_compositeCard;<br />
}<br />
@property (nonatomic, retain) NSNumber* ac_id; <br />
@property (nonatomic, retain) NSString* ac_file;<br />
@property (nonatomic, retain) NSString* ac_typefile;<br />
@property (nonatomic, retain) NSString* ac_author;<br />
@property (nonatomic, retain) NSString* ac_title_topic;<br />
@property (nonatomic, retain) NSString* ac_year;<br />
@property (nonatomic, retain) NSString* ac_technical;<br />
@property (nonatomic, retain) NSString* ac_support_media;<br />
@property (nonatomic, retain) NSString* ac_format;<br />
@property (nonatomic, retain) NSString* ac_owner;<br />
@property (nonatomic, retain) NSString* ac_collection;<br />
@property (nonatomic, retain) NSString* ac_descritpion_remarks;<br />
@property (nonatomic, retain) CompositeCard* ac_compositeCard;<br />
@end<br />




Data.m
<br />
#import &quot;Data.h&quot;<br />
@implementation Data<br />
@synthesize ac_id = _ac_id;<br />
@synthesize ac_file = _ac_file;<br />
@synthesize ac_typefile = _ac_typefile;<br />
@synthesize ac_author = _ac_author;<br />
@synthesize ac_title_topic = _ac_title_topic;<br />
@synthesize ac_year = _ac_year;<br />
@synthesize ac_technical = _ac_technical;<br />
@synthesize ac_support_media = _ac_support_media;<br />
@synthesize ac_format = _ac_format;<br />
@synthesize ac_owner = _ac_owner;<br />
@synthesize ac_collection = _ac_collection;<br />
@synthesize ac_descritpion_remarks = _ac_descritpion_remarks;<br />
@synthesize ac_compositeCard = _ac_compositeCard;<br />
@end<br />




CompositeCard.h
<br />
#import &lt;Foundation/Foundation.h&gt;<br />
@interface CompositeCard : NSObject{<br />
    NSNumber* _cc_id;<br />
    NSString* _cc_name;<br />
}<br />
@property (nonatomic, retain) NSNumber* cc_id; <br />
@property (nonatomic, retain) NSString* cc_name;<br />
@end<br />




CompositeCard.m
<br />
#import &quot;CompositeCard.h&quot;<br />
@implementation CompositeCard<br />
@synthesize cc_id = _cc_id;<br />
@synthesize cc_name = _cc_name;<br />
@end<br />






Merci d'avance.
Mots clés:

Réponses

  • Tu as sans doute déjà  résolu ton problème (il y a d'autres posts).

    La prochaine fois, si tu veux obtenir plus de réponse que 0, il suffit d'expliquer l'erreur qui se produit :
    • informations relative à  l'erreur -> nous avons des indices
    • que du code source -> beaucoup de trucs à  lire sans aucun indice -> on passe au post suivant
Connectez-vous ou Inscrivez-vous pour répondre.