2013-01-23 14 views
24

मैं restkit api सीख रहा हूँ। मुझे बहुत अच्छा Raywenderlich रेस्टकिट ट्यूटोरियल मिला। लेकिन यह Restkit 0.10.1 के साथ एकीकृत है। और मैं एक RestKit-0.20.0-pre6 सीखना चाहता हूँ। यदि किसी के पास आईओएस में इस तरह का अच्छा ट्यूटोरियल है। कृपया बाँटें। अग्रिम में धन्यवाद।क्या रेवेन्डरलिच जैसे कोई रेस्टकिट 2.0 ट्यूटोरियल है?

उत्तर

47

नई RestKit के लिए अंत में Raywenderlich अपडेट किया गया है ट्यूटोरियल http://www.raywenderlich.com/58682/introduction-restkit-tutorial

RestKit 0,20 http://blog.alexedge.co.uk/introduction-to-restkit-0-20/

Reskit 0.20 ट्यूटोरियल https://github.com/RestKit/RKGist/blob/master/TUTORIAL.md

RestKit साथ RESTful iOS ऐप्स का विकास ब्लेक वाट द्वारा ईआरएस http://code.tutsplus.com/tutorials/restkit_ios-sdk--mobile-4524 http://code.tutsplus.com/tutorials/advanced-restkit-development_iphone-sdk--mobile-5916

http://madeveloper.blogspot.com/2013/01/ios-restkit-tutorial-code-for-version.html

अंत में हमेशा पालन :) https://github.com/RestKit/RestKit/wiki

NSScreen एक भुगतान सेवा है, लेकिन इसके कोड के लिए स्वतंत्र हैं - https://github.com/subdigital/nsscreencast

NSScreencast ट्यूटोरियल -

http://nsscreencast.com/episodes/53-restkit-object-manager

http://nsscreencast.com/episodes/52-restkit-coredata

http://nsscreencast.com/episodes/51-intro-to-restkit-mapping

+0

एलेक्सडेज से पहले लिंक को ठीक करना: https://github.com/RestKit/RestKit/issues/832 और उसके बाद बिल्ड चरणों से स्क्रिप्ट को हटाएं –

+2

इस साइट को भी देखें http://restkit-tutorials.com –

+0

वहां है CoreData https://medium.com/ios-os-x-development/restkit-tutorial-how-to-fetch-data-from-an-api-into-core के साथ RestKit का उपयोग करने पर फरवरी 2015 तक एक नया नया ट्यूटोरियल डाटा-9326af750e10 – ZviBar

4

मुझे RestKit 0.20 के साथ काम करने के लिए नीचे दिया गया कोड मिला।

स्थान.एम, location.m, Venue.m, और Venue.h के लिए RayWenderlich के ट्यूटोरियल में पाया गया दूसरा कोड अभी भी सही होना चाहिए।

// 
// MasterViewController.m 
// CoffeeShop 
// 
// 
// Copyright (c) 2013 uihelpers. All rights reserved. 
// 

#import "MasterViewController.h" 
#import <RestKit/RestKit.h> 
#import "Venue.h" 
#import "Location.h" 


#define kCLIENTID "REPLACE_WITH_OWN_ID" 
#define kCLIENTSECRET "REPLACE_WITH_OWN_SECRET" 

@interface MasterViewController() { 
    NSMutableArray *_objects; 
    NSArray *cafeArray; 
} 
@end 

@implementation MasterViewController 

- (void)awakeFromNib 
{ 
    [super awakeFromNib]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    self.navigationItem.leftBarButtonItem = self.editButtonItem; 

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)]; 
    self.navigationItem.rightBarButtonItem = addButton; 

    NSURL *baseURL = [NSURL URLWithString:@"https://api.foursquare.com/v2"]; 

    AFHTTPClient * client = [AFHTTPClient clientWithBaseURL:baseURL]; 
    [client setDefaultHeader:@"Accept" value:RKMIMETypeJSON]; 

    RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client]; 

    RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Venue class]]; 
    [venueMapping addAttributeMappingsFromDictionary:@{ 
    @"name" : @"name" 
    }]; 

    RKObjectMapping *locationMapping = [RKObjectMapping mappingForClass:[Location class]]; 
    [locationMapping addAttributeMappingsFromDictionary:@{ @"address": @"address", @"city": @"city", @"country": @"country", @"crossStreet": @"crossStreet", @"postalCode": @"postalCode", @"state": @"state", @"distance": @"distance", @"lat": @"lat", @"lng": @"lng"}]; 

    /*[venueMapping mapRelationship:@"location" withMapping:locationMapping]; 
    [objectManager.mappingProvider setMapping:locationMapping forKeyPath:@"location"];*/ 

    [venueMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"location" toKeyPath:@"location" withMapping:locationMapping]]; 



    RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:venueMapping 
                        pathPattern:nil 
                        keyPath:@"response.venues" 
                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 
    [objectManager addResponseDescriptor:responseDescriptor]; 

    NSString *latLon = @"37.33,-122.03"; 
    NSString *clientID = [NSString stringWithUTF8String:kCLIENTID]; 
    NSString *clientSecret = [NSString stringWithUTF8String:kCLIENTSECRET]; 

    NSDictionary *queryParams; 
    queryParams = [NSDictionary dictionaryWithObjectsAndKeys:latLon, @"ll", clientID, @"client_id", clientSecret, @"client_secret", @"coffee", @"query", @"20120602", @"v", nil]; 






    [objectManager getObjectsAtPath:@"https://api.foursquare.com/v2/venues/search" 
         parameters:queryParams 
          success:^(RKObjectRequestOperation * operaton, RKMappingResult *mappingResult) 
    { 
     //NSLog(@"success: mappings: %@", mappingResult); 
     NSArray *result = [mappingResult array]; 
     cafeArray = [mappingResult array]; 
     for (Venue *item in result) { 
      NSLog(@"name=%@",item.name); 
      NSLog(@"name=%@",item.location.distance); 

     } 
     [self.tableView reloadData]; 
    } 
          failure:^(RKObjectRequestOperation * operaton, NSError * error) 
    { 
     NSLog (@"failure: operation: %@ \n\nerror: %@", operaton, error); 
    }]; 


} 


- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (void)insertNewObject:(id)sender 
{ 
    if (!_objects) { 
     _objects = [[NSMutableArray alloc] init]; 
    } 
    [_objects insertObject:[NSDate date] atIndex:0]; 
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 

#pragma mark - Table View 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return cafeArray.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

    /*NSDate *object = [_objects objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [object description];*/ 
    Venue *venueObject = [cafeArray objectAtIndex: indexPath.row]; 

    cell.textLabel.text = [venueObject.name length] > 24 ? [venueObject.name substringToIndex:24] : venueObject.name; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%.0fm", [venueObject.location.distance floatValue]]; 

    return cell; 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [_objects removeObjectAtIndex:indexPath.row]; 
     [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
    } 
} 

/* 
// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
} 
*/ 

/* 
// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the item to be re-orderable. 
    return YES; 
} 
*/ 

@end 

इस ट्यूटोरियल भी मदद कर सकता है:

http://madeveloper.blogspot.com/2013/01/ios-restkit-tutorial-code-for-version.html

+0

बहुत अच्छा ट्यूटोरियल। धन्यवाद। – Rajesh

+0

ठंडा ... बहुत उपयोगी .. बहुत बहुत धन्यवाद। – JAHelia

0

मैं एक ऐसी ही प्रश्न पूछा और इसे बाहर काम करने के लिए बस के रूप में किसी ने मुझे जवाब दिया कामयाब रहे! ठेठ!

यहाँ एक त्वरित नज़र Restkit 0.20 basic operation

संबंधित मुद्दे