Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
raja nusantara
Courses Plus Student 2,084 PointsAFNetworking Error.
Hello guys, i had a problem regarding how to parsing a data using AFNetworking from NSArray to NSString :
Here is my DetailViewController.h :
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
@end
and here is my DetailViewController.m
#import "DetailViewController.h"
#import "AFNetworking.h"
@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://blog.teamtreehouse.com/api/get_recent_summary/" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *data = [responseObject valueForKeyPath:@"posts.title"];
self.textField.text = data;
NSLog(@"JSON: %@", data);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Actually it's not actually an error because there is no error with my code. But when i'm running this code i will get a breakpoint/warning which said "incompatible pointer types assigning to nsstring from nsarray" on this line self.textField.text = data;
1 Answer
raja nusantara
Courses Plus Student 2,084 PointsNevermind, I found solution by replacing NSArray *data = [responseObject valueForKeyPath:@"posts.title"]; with NSString *data = [[responseObject valueForKeyPath:@"posts.title"] componentsJoinedByString:@""];