diff --git a/iTunesSearch.xcodeproj/project.pbxproj b/iTunesSearch.xcodeproj/project.pbxproj index 79e06d7..973c7d6 100644 --- a/iTunesSearch.xcodeproj/project.pbxproj +++ b/iTunesSearch.xcodeproj/project.pbxproj @@ -17,6 +17,9 @@ 92C21CE11AAE76930052ABE6 /* TableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CDF1AAE76930052ABE6 /* TableViewCell.m */; }; 92C21CE21AAE76930052ABE6 /* TableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 92C21CE01AAE76930052ABE6 /* TableViewCell.xib */; }; 92C21CE81AAE858E0052ABE6 /* Filme.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CE71AAE858E0052ABE6 /* Filme.m */; }; + E43A1D211AB11745001F3A14 /* Musica.m in Sources */ = {isa = PBXBuildFile; fileRef = E43A1D201AB11745001F3A14 /* Musica.m */; }; + E43A1D241AB1175B001F3A14 /* Podcast.m in Sources */ = {isa = PBXBuildFile; fileRef = E43A1D231AB1175B001F3A14 /* Podcast.m */; }; + E43A1D271AB11778001F3A14 /* Ebook.m in Sources */ = {isa = PBXBuildFile; fileRef = E43A1D261AB11778001F3A14 /* Ebook.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -49,6 +52,12 @@ 92C21CE01AAE76930052ABE6 /* TableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TableViewCell.xib; sourceTree = ""; }; 92C21CE61AAE858E0052ABE6 /* Filme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Filme.h; path = Entidades/Filme.h; sourceTree = ""; }; 92C21CE71AAE858E0052ABE6 /* Filme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Filme.m; path = Entidades/Filme.m; sourceTree = ""; }; + E43A1D1F1AB11745001F3A14 /* Musica.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Musica.h; path = Entidades/Musica.h; sourceTree = ""; }; + E43A1D201AB11745001F3A14 /* Musica.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Musica.m; path = Entidades/Musica.m; sourceTree = ""; }; + E43A1D221AB1175B001F3A14 /* Podcast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Podcast.h; path = Entidades/Podcast.h; sourceTree = ""; }; + E43A1D231AB1175B001F3A14 /* Podcast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Podcast.m; path = Entidades/Podcast.m; sourceTree = ""; }; + E43A1D251AB11778001F3A14 /* Ebook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Ebook.h; path = Entidades/Ebook.h; sourceTree = ""; }; + E43A1D261AB11778001F3A14 /* Ebook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Ebook.m; path = Entidades/Ebook.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -146,6 +155,12 @@ children = ( 92C21CE61AAE858E0052ABE6 /* Filme.h */, 92C21CE71AAE858E0052ABE6 /* Filme.m */, + E43A1D1F1AB11745001F3A14 /* Musica.h */, + E43A1D201AB11745001F3A14 /* Musica.m */, + E43A1D221AB1175B001F3A14 /* Podcast.h */, + E43A1D231AB1175B001F3A14 /* Podcast.m */, + E43A1D251AB11778001F3A14 /* Ebook.h */, + E43A1D261AB11778001F3A14 /* Ebook.m */, ); name = Entidades; sourceTree = ""; @@ -250,7 +265,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + E43A1D271AB11778001F3A14 /* Ebook.m in Sources */, 92C21CBC1AAE757A0052ABE6 /* TableViewController.m in Sources */, + E43A1D211AB11745001F3A14 /* Musica.m in Sources */, + E43A1D241AB1175B001F3A14 /* Podcast.m in Sources */, 92C21CDB1AAE75B30052ABE6 /* iTunesManager.m in Sources */, 92C21CB91AAE757A0052ABE6 /* AppDelegate.m in Sources */, 92C21CE81AAE858E0052ABE6 /* Filme.m in Sources */, diff --git a/iTunesSearch/AppDelegate.m b/iTunesSearch/AppDelegate.m index d513fd8..55987a1 100644 --- a/iTunesSearch/AppDelegate.m +++ b/iTunesSearch/AppDelegate.m @@ -22,6 +22,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( #warning Necessário para inicializar a aplicacao sem storyboard self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; diff --git a/iTunesSearch/Entidades/Ebook.h b/iTunesSearch/Entidades/Ebook.h new file mode 100644 index 0000000..a7d6834 --- /dev/null +++ b/iTunesSearch/Entidades/Ebook.h @@ -0,0 +1,20 @@ +// +// Ebook.h +// iTunesSearch +// +// Created by Isaías Lima on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import + +@interface Ebook : NSObject + +@property (nonatomic, strong) NSString *nome; +@property (nonatomic, strong) NSString *artista; +@property (nonatomic, strong) NSNumber *duracao; +@property (nonatomic, strong) NSString *genero; +@property (nonatomic, strong) NSString *pais; +@property (nonatomic, strong) NSString *lancamento; + +@end diff --git a/iTunesSearch/Entidades/Ebook.m b/iTunesSearch/Entidades/Ebook.m new file mode 100644 index 0000000..8cb3d98 --- /dev/null +++ b/iTunesSearch/Entidades/Ebook.m @@ -0,0 +1,13 @@ +// +// Ebook.m +// iTunesSearch +// +// Created by Isaías Lima on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Ebook.h" + +@implementation Ebook + +@end diff --git a/iTunesSearch/Entidades/Filme.h b/iTunesSearch/Entidades/Filme.h index eb126dc..8881751 100644 --- a/iTunesSearch/Entidades/Filme.h +++ b/iTunesSearch/Entidades/Filme.h @@ -11,10 +11,10 @@ @interface Filme : NSObject @property (nonatomic, strong) NSString *nome; -@property (nonatomic, strong) NSString *trackId; @property (nonatomic, strong) NSString *artista; -@property (nonatomic, strong) NSString *duracao; +@property (nonatomic, strong) NSNumber *duracao; @property (nonatomic, strong) NSString *genero; @property (nonatomic, strong) NSString *pais; +@property (nonatomic, strong) NSString *lancamento; @end diff --git a/iTunesSearch/Entidades/Musica.h b/iTunesSearch/Entidades/Musica.h new file mode 100644 index 0000000..c2e8e0e --- /dev/null +++ b/iTunesSearch/Entidades/Musica.h @@ -0,0 +1,20 @@ +// +// Musica.h +// iTunesSearch +// +// Created by Isaías Lima on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import + +@interface Musica : NSObject + +@property (nonatomic, strong) NSString *nome; +@property (nonatomic, strong) NSString *artista; +@property (nonatomic, strong) NSNumber *duracao; +@property (nonatomic, strong) NSString *genero; +@property (nonatomic, strong) NSString *pais; +@property (nonatomic, strong) NSString *lancamento; + +@end diff --git a/iTunesSearch/Entidades/Musica.m b/iTunesSearch/Entidades/Musica.m new file mode 100644 index 0000000..d52d62e --- /dev/null +++ b/iTunesSearch/Entidades/Musica.m @@ -0,0 +1,14 @@ +// +// Musica.m +// iTunesSearch +// +// Created by Isaías Lima on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Musica.h" + +@implementation Musica + + +@end diff --git a/iTunesSearch/Entidades/Podcast.h b/iTunesSearch/Entidades/Podcast.h new file mode 100644 index 0000000..8914692 --- /dev/null +++ b/iTunesSearch/Entidades/Podcast.h @@ -0,0 +1,20 @@ +// +// Podcast.h +// iTunesSearch +// +// Created by Isaías Lima on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import + +@interface Podcast : NSObject + +@property (nonatomic, strong) NSString *nome; +@property (nonatomic, strong) NSString *artista; +@property (nonatomic, strong) NSNumber *duracao; +@property (nonatomic, strong) NSString *genero; +@property (nonatomic, strong) NSString *pais; +@property (nonatomic, strong) NSString *lancamento; + +@end diff --git a/iTunesSearch/Entidades/Podcast.m b/iTunesSearch/Entidades/Podcast.m new file mode 100644 index 0000000..d2e49b2 --- /dev/null +++ b/iTunesSearch/Entidades/Podcast.m @@ -0,0 +1,13 @@ +// +// Podcast.m +// iTunesSearch +// +// Created by Isaías Lima on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Podcast.h" + +@implementation Podcast + +@end diff --git a/iTunesSearch/TableView.xib b/iTunesSearch/TableView.xib index 55f128c..f00ed6f 100644 --- a/iTunesSearch/TableView.xib +++ b/iTunesSearch/TableView.xib @@ -1,11 +1,14 @@ - + + + + @@ -15,11 +18,51 @@ + + + + + + + + + Title + Title + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + diff --git a/iTunesSearch/TableViewCell.h b/iTunesSearch/TableViewCell.h index b630349..1be7e99 100644 --- a/iTunesSearch/TableViewCell.h +++ b/iTunesSearch/TableViewCell.h @@ -11,7 +11,12 @@ @interface TableViewCell : UITableViewCell @property (weak, nonatomic) IBOutlet UILabel *nome; -@property (weak, nonatomic) IBOutlet UILabel *tipo; +@property (weak, nonatomic) IBOutlet UILabel *artista; +@property (weak, nonatomic) IBOutlet UILabel *duracao; +@property (weak, nonatomic) IBOutlet UILabel *genero; +@property (weak, nonatomic) IBOutlet UILabel *pais; +@property (weak, nonatomic) IBOutlet UILabel *lancamento; + @end diff --git a/iTunesSearch/TableViewCell.xib b/iTunesSearch/TableViewCell.xib index bf8bd3f..8faa96f 100644 --- a/iTunesSearch/TableViewCell.xib +++ b/iTunesSearch/TableViewCell.xib @@ -1,5 +1,5 @@ - + @@ -7,40 +7,80 @@ - - + + - - - + + + + + + + + + - + + + + + + + + + + - + - + diff --git a/iTunesSearch/TableViewController.h b/iTunesSearch/TableViewController.h index 0cbb5c4..a16bc6c 100644 --- a/iTunesSearch/TableViewController.h +++ b/iTunesSearch/TableViewController.h @@ -8,10 +8,14 @@ #import -@interface TableViewController : UIViewController +@interface TableViewController : UIViewController +@property (strong, nonatomic) IBOutlet UISearchBar *busca; @property (strong, nonatomic) IBOutlet UITableView *tableview; +@property (strong, nonatomic) IBOutlet UIView *header; + + @end diff --git a/iTunesSearch/TableViewController.m b/iTunesSearch/TableViewController.m index f689980..5b58c8e 100644 --- a/iTunesSearch/TableViewController.m +++ b/iTunesSearch/TableViewController.m @@ -10,14 +10,17 @@ #import "TableViewCell.h" #import "iTunesManager.h" #import "Entidades/Filme.h" +#import "Entidades/Musica.h" +#import "Entidades/Podcast.h" +#import "Entidades/Ebook.h" -@interface TableViewController () { - NSArray *midias; -} +@interface TableViewController () @end -@implementation TableViewController +@implementation TableViewController { + iTunesManager *itunes; +} @@ -27,11 +30,17 @@ - (void)viewDidLoad { UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil]; [self.tableview registerNib:nib forCellReuseIdentifier:@"celulaPadrao"]; - iTunesManager *itunes = [iTunesManager sharedInstance]; - midias = [itunes buscarMidias:@"Apple"]; + itunes = [iTunesManager sharedInstance]; + #warning Necessario para que a table view tenha um espaco em relacao ao topo, pois caso contrario o texto ficara atras da barra superior - self.tableview.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableview.bounds.size.width, 15.f)]; + + + + + _busca.translucent = YES; + + [_busca resignFirstResponder]; } - (void)didReceiveMemoryWarning { @@ -42,27 +51,141 @@ - (void)didReceiveMemoryWarning { #pragma mark - Metodos do UITableViewDataSource -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; + return 4; +} + +//-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { +// NSArray *sectionNames = [[NSArray alloc] initWithObjects:@"Filmes", @"Músicas", @"Podcasts", @"Ebooks", nil]; +// return sectionNames; +//} + +-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { + NSString *title; + switch (section) { + case 0: + title = @"Filmes"; + break; + + case 1: + title = @"Músicas"; + break; + + case 2: + title = @"Podcasts"; + break; + + case 3: + title = @"Ebook"; + break; + + default: + break; + } + return title; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [midias count]; + NSInteger count; + switch (section) { + case 0: + count = [itunes.filmes count]; + break; + + case 1: + count = [itunes.musicas count]; + break; + + case 2: + count = [itunes.podcasts count]; + break; + + case 3: + count = [itunes.ebooks count]; + break; + + default: + break; + } + return count; +} + +-(BOOL) prefersStatusBarHidden { + return YES; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - TableViewCell *celula = [self.tableview dequeueReusableCellWithIdentifier:@"celulaPadrao"]; - Filme *filme = [midias objectAtIndex:indexPath.row]; - - [celula.nome setText:filme.nome]; - [celula.tipo setText:@"Filme"]; +// NSMutableArray *aux = [itunes.dados objectAtIndex:(indexPath.section)]; + TableViewCell *celula = [[TableViewCell alloc] init]; + celula = [self.tableview dequeueReusableCellWithIdentifier:@"celulaPadrao"]; + + if (indexPath.section == 0) { + Filme *mid = [[itunes filmes]objectAtIndex:indexPath.row]; +// Filme *mid = [aux objectAtIndex:indexPath.row]; + [celula.nome setText:mid.nome]; + [celula.artista setText:mid.artista]; + [celula.duracao setText: [NSString stringWithFormat:@"%d min", [mid.duracao intValue]/6000]]; + [celula.genero setText:mid.genero]; + [celula.pais setText:mid.pais]; + [celula.lancamento setText:mid.lancamento]; + } + else if (indexPath.section == 1) { + Musica *mid = [[itunes musicas]objectAtIndex:indexPath.row]; +// Musica *mid = [aux objectAtIndex:indexPath.row]; + [celula.nome setText:mid.nome]; + [celula.artista setText:mid.artista]; + [celula.duracao setText: [NSString stringWithFormat:@"%d min", [mid.duracao intValue]/6000]]; + [celula.genero setText:mid.genero]; + [celula.pais setText:mid.pais]; + [celula.lancamento setText:mid.lancamento]; + } + else if (indexPath.section == 2) { + Podcast *mid = [[itunes podcasts]objectAtIndex:indexPath.row]; +// Podcast *mid = [aux objectAtIndex:indexPath.row]; + [celula.nome setText:mid.nome]; + [celula.artista setText:mid.artista]; + [celula.duracao setText: [NSString stringWithFormat:@"%d min", [mid.duracao intValue]/6000]]; + [celula.genero setText:mid.genero]; + [celula.pais setText:mid.pais]; + [celula.lancamento setText:mid.lancamento]; + } + else if (indexPath.section == 3) { + Ebook *mid = [[itunes ebooks]objectAtIndex:indexPath.row]; +// Ebook *mid = [aux objectAtIndex:indexPath.row]; + [celula.nome setText:mid.nome]; + [celula.artista setText:mid.artista]; + [celula.duracao setText:@" "]; + [celula.genero setText:mid.genero]; + [celula.pais setText:mid.pais]; + [celula.lancamento setText:mid.lancamento]; + } return celula; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - return 70; + return 200; } + +-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { + searchBar = _busca; + NSString *termo = [[NSString alloc] init]; + termo = searchBar.text; + + NSError *error = NULL; + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^[A-Z0-9a-z]{1,100}$" options:NSRegularExpressionCaseInsensitive error:&error]; + NSUInteger numberOfMatches = [regex numberOfMatchesInString:termo options:0 range:NSMakeRange(0, [termo length])]; + + if (!numberOfMatches) { + UIAlertView *alerta = [[UIAlertView alloc] initWithTitle:@"Alerta" message:@"Caracteres inválidos" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; + [alerta show]; + return; + } + + [itunes buscarMidias:termo]; + [searchBar endEditing:YES]; + [self.tableview reloadData]; +} @end diff --git a/iTunesSearch/iTunesManager.h b/iTunesSearch/iTunesManager.h index c0e366b..d9c163a 100644 --- a/iTunesSearch/iTunesManager.h +++ b/iTunesSearch/iTunesManager.h @@ -10,12 +10,20 @@ @interface iTunesManager : NSObject +@property NSArray *dados; + +@property NSMutableArray *filmes; +@property NSMutableArray *musicas; +@property NSMutableArray *ebooks; +@property NSMutableArray *podcasts; + + /** * gets singleton object. * @return singleton */ + (iTunesManager*)sharedInstance; -- (NSArray *)buscarMidias:(NSString *)termo; +- (void)buscarMidias:(NSString *)termo; @end diff --git a/iTunesSearch/iTunesManager.m b/iTunesSearch/iTunesManager.m index e2babda..27e820e 100644 --- a/iTunesSearch/iTunesManager.m +++ b/iTunesSearch/iTunesManager.m @@ -8,6 +8,10 @@ #import "iTunesManager.h" #import "Entidades/Filme.h" +#import "Entidades/Musica.h" +#import "Entidades/Podcast.h" +#import "Entidades/Ebook.h" +#import @implementation iTunesManager @@ -29,38 +33,170 @@ + (id)sharedInstance } -- (NSArray *)buscarMidias:(NSString *)termo { +- (void)buscarMidias:(NSString *)termo { if (!termo) { termo = @""; } - NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=movie", termo]; - NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:url]]; + @try { + NSString *midia = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=all", termo]; + NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:midia]]; + + NSError *error; + NSDictionary *midias = [NSJSONSerialization JSONObjectWithData:jsonData + options:NSJSONReadingMutableContainers + error:&error]; + if (error) { + NSLog(@"Não foi possível fazer a busca. ERRO: %@", error); + } + + NSArray *resultados = [midias objectForKey:@"results"]; + +// NSMutableArray *filmes = [[NSMutableArray alloc] init]; +// NSMutableArray *musicas = [[NSMutableArray alloc] init];; +// NSMutableArray *podcastes = [[NSMutableArray alloc] init];; +// NSMutableArray *ebookes = [[NSMutableArray alloc] init]; + + _filmes = [[NSMutableArray alloc] init]; + _musicas = [[NSMutableArray alloc] init];; + _podcasts = [[NSMutableArray alloc] init];; + _ebooks = [[NSMutableArray alloc] init]; + + NSString *ano = [[NSString alloc] init]; + + for (NSDictionary *item in resultados) { + if ([[item objectForKey:@"kind"] isEqual:@"feature-movie"]) { + Filme *filme = [[Filme alloc] init]; + [filme setNome:[item objectForKey:@"trackName"]]; + [filme setArtista:[item objectForKey:@"artistName"]]; + [filme setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [filme setGenero:[item objectForKey:@"primaryGenreName"]]; + [filme setPais:[item objectForKey:@"country"]]; + + NSString *year = [item objectForKey:@"releaseDate"]; + ano = [year substringToIndex:4]; + + [filme setLancamento:ano]; + + [_filmes addObject:filme]; + } + else if ([[item objectForKey:@"kind"] isEqual:@"song"]) { + Musica *musica = [[Musica alloc] init]; + [musica setNome:[item objectForKey:@"trackName"]]; + [musica setArtista:[item objectForKey:@"artistName"]]; + [musica setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [musica setGenero:[item objectForKey:@"primaryGenreName"]]; + [musica setPais:[item objectForKey:@"country"]]; + + NSString *year = [item objectForKey:@"releaseDate"]; + ano = [year substringToIndex:4]; + + [musica setLancamento:ano]; + + [_musicas addObject:musica]; + } + else if ([[item objectForKey:@"kind"] isEqual:@"podcast"]) { + Podcast *podcast = [[Podcast alloc] init]; + [podcast setNome:[item objectForKey:@"trackName"]]; + [podcast setArtista:[item objectForKey:@"artistName"]]; + [podcast setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [podcast setGenero:[item objectForKey:@"primaryGenreName"]]; + [podcast setPais:[item objectForKey:@"country"]]; - NSError *error; - NSDictionary *resultado = [NSJSONSerialization JSONObjectWithData:jsonData - options:NSJSONReadingMutableContainers - error:&error]; - if (error) { - NSLog(@"Não foi possível fazer a busca. ERRO: %@", error); - return nil; - } + NSString *year = [item objectForKey:@"releaseDate"]; + ano = [year substringToIndex:4]; - NSArray *resultados = [resultado objectForKey:@"results"]; - NSMutableArray *filmes = [[NSMutableArray alloc] init]; + [podcast setLancamento:ano]; - for (NSDictionary *item in resultados) { - Filme *filme = [[Filme alloc] init]; - [filme setNome:[item objectForKey:@"trackName"]]; - [filme setTrackId:[item objectForKey:@"trackId"]]; - [filme setArtista:[item objectForKey:@"artistName"]]; - [filme setDuracao:[item objectForKey:@"trackTimeMillis"]]; - [filme setGenero:[item objectForKey:@"primaryGenreName"]]; - [filme setPais:[item objectForKey:@"country"]]; - [filmes addObject:filme]; + [_podcasts addObject:podcast]; + } + else if ([[item objectForKey:@"kind"] isEqual:@"ebook"]) { + Ebook *ebook = [[Ebook alloc] init]; + [ebook setNome:[item objectForKey:@"trackName"]]; + [ebook setArtista:[item objectForKey:@"artistName"]]; + [ebook setDuracao:0]; + [ebook setGenero:[item objectForKey:@"primaryGenreName"]]; + [ebook setPais:[item objectForKey:@"country"]]; + + NSString *year = [item objectForKey:@"releaseDate"]; + ano = [year substringToIndex:4]; + + [ebook setLancamento:ano]; + + [_ebooks addObject:ebook]; + } + } + + + +// for (NSDictionary *item in resultadosmovie) { +// Filme *filme = [[Filme alloc] init]; +// [filme setNome:[item objectForKey:@"trackName"]]; +// [filme setArtista:[item objectForKey:@"artistName"]]; +// [filme setDuracao:[item objectForKey:@"trackTimeMillis"]]; +// [filme setGenero:[item objectForKey:@"primaryGenreName"]]; +// [filme setPais:[item objectForKey:@"country"]]; +// +// NSString *year = [item objectForKey:@"releaseDate"]; +// ano = [year substringToIndex:4]; +// +// [filme setLancamento:ano]; +// +// +// [filmes addObject:filme]; +// } +// for (NSDictionary *item in resultadosmusic) { +// Musica *musica = [[Musica alloc] init]; +// [musica setNome:[item objectForKey:@"trackName"]]; +// [musica setArtista:[item objectForKey:@"artistName"]]; +// [musica setDuracao:[item objectForKey:@"trackTimeMillis"]]; +// [musica setGenero:[item objectForKey:@"primaryGenreName"]]; +// [musica setPais:[item objectForKey:@"country"]]; +// +// NSString *year = [item objectForKey:@"releaseDate"]; +// ano = [year substringToIndex:4]; +// +// [musica setLancamento:ano]; +// +// [musicas addObject:musica]; +// } +// for (NSDictionary *item in resultadospodcast) { +// Podcast *podcast = [[Podcast alloc] init]; +// [podcast setNome:[item objectForKey:@"trackName"]]; +// [podcast setArtista:[item objectForKey:@"artistName"]]; +// [podcast setDuracao:[item objectForKey:@"trackTimeMillis"]]; +// [podcast setGenero:[item objectForKey:@"primaryGenreName"]]; +// [podcast setPais:[item objectForKey:@"country"]]; +// +// NSString *year = [item objectForKey:@"releaseDate"]; +// ano = [year substringToIndex:4]; +// +// [podcast setLancamento:ano]; +// +// [podcastes addObject:podcast]; +// } +// for (NSDictionary *item in resultadosebook) { +// Ebook *ebook = [[Ebook alloc] init]; +// [ebook setNome:[item objectForKey:@"trackName"]]; +// [ebook setArtista:[item objectForKey:@"artistName"]]; +// [ebook setDuracao:0]; +// [ebook setGenero:[item objectForKey:@"primaryGenreName"]]; +// [ebook setPais:[item objectForKey:@"country"]]; +// +// NSString *year = [item objectForKey:@"releaseDate"]; +// ano = [year substringToIndex:4]; +// +// [ebook setLancamento:ano]; +// +// [ebookes addObject:ebook]; +// } + +// _dados = [[NSArray alloc] initWithObjects:filmes, musicas, podcastes, ebookes, nil]; + } + @catch (NSException *exception) { + UIAlertView *alerta = [[UIAlertView alloc] initWithTitle:@"Alerta" message:@"Termo não encontrado" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; + [alerta show]; } - - return filmes; }