From cb6cdebacbdcc5c5906bd5f6bb515eacfa0007be Mon Sep 17 00:00:00 2001 From: astha-iOS Date: Sat, 5 Jun 2021 12:27:47 +0530 Subject: [PATCH 1/3] fix bug in listing page and added detail page --- .gitignore | 10 + codeChallenge.xcodeproj/project.pbxproj | 104 +++++++- .../xcdebugger/Breakpoints_v2.xcbkptlist | 36 +++ .../xcschemes/xcschememanagement.plist | 14 ++ codeChallenge/ApiManager/Constant.h | 11 + codeChallenge/ApiManager/RestApi.swift | 48 ++++ codeChallenge/ApiManager/RestClass.h | 31 +++ codeChallenge/ApiManager/RestClass.m | 59 +++++ codeChallenge/AppDelegate.h | 1 + codeChallenge/Base.lproj/Main.storyboard | 234 +++++++++++++++++- codeChallenge/CommonMethods.h | 19 ++ codeChallenge/CommonMethods.m | 35 +++ codeChallenge/CustomCell.m | 22 -- codeChallenge/Info.plist | 5 + codeChallenge/Modal/PhotosModal.h | 51 ++++ codeChallenge/Modal/PhotosModal.m | 38 +++ codeChallenge/PCH/PrefixHeader.pch | 24 ++ codeChallenge/ViewController.m | 122 --------- .../ViewControllers/DetailViewController.h | 31 +++ .../ViewControllers/DetailViewController.m | 60 +++++ .../{ => ViewControllers}/ViewController.h | 4 + .../ViewControllers/ViewController.m | 179 ++++++++++++++ codeChallenge/{ => Views}/CustomCell.h | 3 + codeChallenge/Views/CustomCell.m | 39 +++ codeChallenge/{ => Views}/CustomCell.xib | 38 ++- codeChallenge/codeChallenge-Bridging-Header.h | 4 + 26 files changed, 1043 insertions(+), 179 deletions(-) create mode 100644 .gitignore create mode 100644 codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist create mode 100644 codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcschemes/xcschememanagement.plist create mode 100644 codeChallenge/ApiManager/Constant.h create mode 100644 codeChallenge/ApiManager/RestApi.swift create mode 100644 codeChallenge/ApiManager/RestClass.h create mode 100644 codeChallenge/ApiManager/RestClass.m create mode 100644 codeChallenge/CommonMethods.h create mode 100644 codeChallenge/CommonMethods.m delete mode 100644 codeChallenge/CustomCell.m create mode 100644 codeChallenge/Modal/PhotosModal.h create mode 100644 codeChallenge/Modal/PhotosModal.m create mode 100644 codeChallenge/PCH/PrefixHeader.pch delete mode 100644 codeChallenge/ViewController.m create mode 100644 codeChallenge/ViewControllers/DetailViewController.h create mode 100644 codeChallenge/ViewControllers/DetailViewController.m rename codeChallenge/{ => ViewControllers}/ViewController.h (58%) create mode 100644 codeChallenge/ViewControllers/ViewController.m rename codeChallenge/{ => Views}/CustomCell.h (88%) create mode 100644 codeChallenge/Views/CustomCell.m rename codeChallenge/{ => Views}/CustomCell.xib (72%) create mode 100644 codeChallenge/codeChallenge-Bridging-Header.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c52d52b --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Mac OS X +.DS_Store + +# Xcode +*.pbxuser +*.perspective +*.perspectivev3 +*.mode1v3 +*.mode2v3 +*.xcuserstate diff --git a/codeChallenge.xcodeproj/project.pbxproj b/codeChallenge.xcodeproj/project.pbxproj index 06a6ec1..324cf91 100644 --- a/codeChallenge.xcodeproj/project.pbxproj +++ b/codeChallenge.xcodeproj/project.pbxproj @@ -7,6 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 0745256A266A3BA800342E43 /* RestApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07452569266A3BA800342E43 /* RestApi.swift */; }; + 074C69BE266B40E700E82DBE /* CommonMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = 074C69BD266B40E700E82DBE /* CommonMethods.m */; }; + 074C69C1266B568500E82DBE /* .gitignore in Resources */ = {isa = PBXBuildFile; fileRef = 074C69C0266B568500E82DBE /* .gitignore */; }; + 0759896926689BA0002129B1 /* RestClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 0759896826689BA0002129B1 /* RestClass.m */; }; + 075989722668A309002129B1 /* PhotosModal.m in Sources */ = {isa = PBXBuildFile; fileRef = 075989712668A309002129B1 /* PhotosModal.m */; }; + 0764840C2668EDEB00022B6F /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0764840B2668EDEB00022B6F /* DetailViewController.m */; }; 3E15BBE4208754FE0029597E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E15BBE3208754FE0029597E /* AppDelegate.m */; }; 3E15BBE7208754FE0029597E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E15BBE6208754FE0029597E /* ViewController.m */; }; 3E15BBEA208754FE0029597E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E15BBE8208754FE0029597E /* Main.storyboard */; }; @@ -18,6 +24,19 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 07452568266A3BA800342E43 /* codeChallenge-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "codeChallenge-Bridging-Header.h"; sourceTree = ""; }; + 07452569266A3BA800342E43 /* RestApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestApi.swift; sourceTree = ""; }; + 074C69BC266B40E700E82DBE /* CommonMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommonMethods.h; sourceTree = ""; }; + 074C69BD266B40E700E82DBE /* CommonMethods.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CommonMethods.m; sourceTree = ""; }; + 074C69C0266B568500E82DBE /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = ""; }; + 0759896726689BA0002129B1 /* RestClass.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RestClass.h; sourceTree = ""; }; + 0759896826689BA0002129B1 /* RestClass.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RestClass.m; sourceTree = ""; }; + 0759896B26689E22002129B1 /* Constant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Constant.h; sourceTree = ""; }; + 075989702668A309002129B1 /* PhotosModal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PhotosModal.h; sourceTree = ""; }; + 075989712668A309002129B1 /* PhotosModal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PhotosModal.m; sourceTree = ""; }; + 076484072668C31600022B6F /* PrefixHeader.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrefixHeader.pch; sourceTree = ""; }; + 0764840A2668EDEB00022B6F /* DetailViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DetailViewController.h; sourceTree = ""; }; + 0764840B2668EDEB00022B6F /* DetailViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DetailViewController.m; sourceTree = ""; }; 3E15BBDF208754FE0029597E /* codeChallenge.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = codeChallenge.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3E15BBE2208754FE0029597E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 3E15BBE3208754FE0029597E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -44,9 +63,59 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 0759896626689B3B002129B1 /* ApiManager */ = { + isa = PBXGroup; + children = ( + 0759896B26689E22002129B1 /* Constant.h */, + 0759896726689BA0002129B1 /* RestClass.h */, + 0759896826689BA0002129B1 /* RestClass.m */, + 07452569266A3BA800342E43 /* RestApi.swift */, + ); + path = ApiManager; + sourceTree = ""; + }; + 0759896D2668A13F002129B1 /* ViewControllers */ = { + isa = PBXGroup; + children = ( + 3E15BBE5208754FE0029597E /* ViewController.h */, + 3E15BBE6208754FE0029597E /* ViewController.m */, + 0764840A2668EDEB00022B6F /* DetailViewController.h */, + 0764840B2668EDEB00022B6F /* DetailViewController.m */, + ); + path = ViewControllers; + sourceTree = ""; + }; + 0759896E2668A170002129B1 /* Views */ = { + isa = PBXGroup; + children = ( + 3E15BBF8208774B10029597E /* CustomCell.h */, + 3E15BBF9208774B10029597E /* CustomCell.m */, + 3E15BBFB20879B4B0029597E /* CustomCell.xib */, + ); + path = Views; + sourceTree = ""; + }; + 0759896F2668A1B1002129B1 /* Modal */ = { + isa = PBXGroup; + children = ( + 075989702668A309002129B1 /* PhotosModal.h */, + 075989712668A309002129B1 /* PhotosModal.m */, + ); + path = Modal; + sourceTree = ""; + }; + 076484062668C30A00022B6F /* PCH */ = { + isa = PBXGroup; + children = ( + 076484072668C31600022B6F /* PrefixHeader.pch */, + ); + path = PCH; + sourceTree = ""; + }; 3E15BBD6208754FE0029597E = { isa = PBXGroup; children = ( + 074C69C0266B568500E82DBE /* .gitignore */, 3E15BBE1208754FE0029597E /* codeChallenge */, 3E15BBE0208754FE0029597E /* Products */, ); @@ -63,18 +132,21 @@ 3E15BBE1208754FE0029597E /* codeChallenge */ = { isa = PBXGroup; children = ( + 076484062668C30A00022B6F /* PCH */, + 0759896F2668A1B1002129B1 /* Modal */, + 0759896626689B3B002129B1 /* ApiManager */, + 0759896E2668A170002129B1 /* Views */, + 0759896D2668A13F002129B1 /* ViewControllers */, 3E15BBE2208754FE0029597E /* AppDelegate.h */, 3E15BBE3208754FE0029597E /* AppDelegate.m */, - 3E15BBE5208754FE0029597E /* ViewController.h */, - 3E15BBE6208754FE0029597E /* ViewController.m */, - 3E15BBF8208774B10029597E /* CustomCell.h */, - 3E15BBF9208774B10029597E /* CustomCell.m */, - 3E15BBFB20879B4B0029597E /* CustomCell.xib */, 3E15BBE8208754FE0029597E /* Main.storyboard */, 3E15BBEB208754FE0029597E /* Assets.xcassets */, 3E15BBED208754FE0029597E /* LaunchScreen.storyboard */, 3E15BBF0208754FE0029597E /* Info.plist */, 3E15BBF1208754FE0029597E /* main.m */, + 07452568266A3BA800342E43 /* codeChallenge-Bridging-Header.h */, + 074C69BC266B40E700E82DBE /* CommonMethods.h */, + 074C69BD266B40E700E82DBE /* CommonMethods.m */, ); path = codeChallenge; sourceTree = ""; @@ -110,6 +182,7 @@ TargetAttributes = { 3E15BBDE208754FE0029597E = { CreatedOnToolsVersion = 9.3; + LastSwiftMigration = 1210; }; }; }; @@ -136,6 +209,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 074C69C1266B568500E82DBE /* .gitignore in Resources */, 3E15BBEF208754FE0029597E /* LaunchScreen.storyboard in Resources */, 3E15BBEC208754FE0029597E /* Assets.xcassets in Resources */, 3E15BBFC20879B4B0029597E /* CustomCell.xib in Resources */, @@ -150,10 +224,15 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 0745256A266A3BA800342E43 /* RestApi.swift in Sources */, + 074C69BE266B40E700E82DBE /* CommonMethods.m in Sources */, + 075989722668A309002129B1 /* PhotosModal.m in Sources */, + 0759896926689BA0002129B1 /* RestClass.m in Sources */, 3E15BBE7208754FE0029597E /* ViewController.m in Sources */, 3E15BBF2208754FE0029597E /* main.m in Sources */, 3E15BBFA208774B10029597E /* CustomCell.m in Sources */, 3E15BBE4208754FE0029597E /* AppDelegate.m in Sources */, + 0764840C2668EDEB00022B6F /* DetailViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -214,12 +293,14 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; + DEFINES_MODULE = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREFIX_HEADER = "/Users/asthayadav/Documents/Orderbird-coding-task/ios-tech-challenge/codeChallenge/PCH/PrefixHeader.pch"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -230,6 +311,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + IBC_MODULE = codeChallenge; IPHONEOS_DEPLOYMENT_TARGET = 11.3; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -272,16 +354,19 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEFINES_MODULE = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; + GCC_PREFIX_HEADER = "/Users/asthayadav/Documents/Orderbird-coding-task/ios-tech-challenge/codeChallenge/PCH/PrefixHeader.pch"; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + IBC_MODULE = codeChallenge; IPHONEOS_DEPLOYMENT_TARGET = 11.3; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; @@ -293,7 +378,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; + DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 56ETNADXPZ; INFOPLIST_FILE = codeChallenge/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -302,6 +389,9 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.nanosuarez.codeChallenge; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "codeChallenge/codeChallenge-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -310,7 +400,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; + DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 56ETNADXPZ; INFOPLIST_FILE = codeChallenge/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -319,6 +411,8 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.nanosuarez.codeChallenge; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "codeChallenge/codeChallenge-Bridging-Header.h"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..166464a --- /dev/null +++ b/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,36 @@ + + + + + + + + + + + + + diff --git a/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcschemes/xcschememanagement.plist b/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..35598e5 --- /dev/null +++ b/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + codeChallenge.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/codeChallenge/ApiManager/Constant.h b/codeChallenge/ApiManager/Constant.h new file mode 100644 index 0000000..7b3b4ce --- /dev/null +++ b/codeChallenge/ApiManager/Constant.h @@ -0,0 +1,11 @@ +// +// Constant.h +// codeChallenge +// +// Created by Astha yadav on 03/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + + + +#define FlickrAPIKey @"2ed35a9f4fda03bc96e73dbd03602780" diff --git a/codeChallenge/ApiManager/RestApi.swift b/codeChallenge/ApiManager/RestApi.swift new file mode 100644 index 0000000..13ec414 --- /dev/null +++ b/codeChallenge/ApiManager/RestApi.swift @@ -0,0 +1,48 @@ +// +// RestApi.swift +// codeChallenge +// +// Created by Astha yadav on 04/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +import Foundation +import UIKit + +class RestApi : NSObject { + + static var sharedInstance:RestApi { + let instance = RestApi() + return instance + } + + @objc func getFlikerPhotosApi(pageNo:Int,perPageCount:Int,sort:String){ + let extra = "date_taken,views,description,date_upload,date_taken,owner_name,icon_server,original_format,last_update,views,media,url_t,url_l" + let BASEURL = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&tags=%@&page=%ld&per_page=%ld&format=json&nojsoncallback=1&sort=%@&extras=%@" + + let urlString : String = String(format:BASEURL,"2ed35a9f4fda03bc96e73dbd03602780","cooking",pageNo,perPageCount,sort,extra) + + let session = URLSession.shared + + guard let url = URL(string: urlString) else { return } + + let task = session.dataTask(with: url, completionHandler: { data, response, error in + if error == nil { + do { + if let jsonData = data { + let json = try JSONSerialization.jsonObject(with: jsonData, options: []) as! [String: Any] + + // print(json) + NotificationCenter.default.post(name: NSNotification.Name(rawValue: "getJSON"), object: self, userInfo: json) + } + } catch { + print(error.localizedDescription) + } + }else{ + print(error?.localizedDescription ?? "Error") + } + }) + task.resume() + } + +} diff --git a/codeChallenge/ApiManager/RestClass.h b/codeChallenge/ApiManager/RestClass.h new file mode 100644 index 0000000..aeb3fad --- /dev/null +++ b/codeChallenge/ApiManager/RestClass.h @@ -0,0 +1,31 @@ +// +// RestClass.h +// codeChallenge +// +// Created by Astha yadav on 03/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol APIDelegates + +@optional +-(void)passRequestedArray:(NSMutableArray*)dataArray WithId:(NSString*)ID; +-(void)errorMessageWithRetry:(NSString*)errorMsg WithId:(NSString*)ID; +@end + +@interface RestClass : NSObject + +@property (nonatomic, weak) id delegate; + +-(id)initWithDelegate:(id)del; + +#pragma mark:flickr Api +-(void)getFlickrPhotoApi:(NSInteger)perPage withPageNumber:(NSInteger)pageNo sortBy:(NSString*)sort; + +@end + +NS_ASSUME_NONNULL_END diff --git a/codeChallenge/ApiManager/RestClass.m b/codeChallenge/ApiManager/RestClass.m new file mode 100644 index 0000000..c6bf860 --- /dev/null +++ b/codeChallenge/ApiManager/RestClass.m @@ -0,0 +1,59 @@ +// +// RestClass.m +// codeChallenge +// +// Created by Astha yadav on 03/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import "RestClass.h" + +@implementation RestClass + +@synthesize delegate; + +- (id)initWithDelegate:(id )del +{ + self = [super init]; + + if (!self) + return nil; + [self setDelegate:del]; + return self; +} + +#pragma mark: flickr Api +-(void)getFlickrPhotoApi:(NSInteger)perPage withPageNumber:(NSInteger)pageNo sortBy:(NSString*)sort{ + NSString *extra = @"date_taken,views,description,date_upload,date_taken,owner_name,icon_server,original_format,last_update,views,media,url_t,url_l"; + + NSString *urlString = [NSString stringWithFormat:@"https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&tags=%@&page=%ld&per_page=%ld&format=json&nojsoncallback=1&sort=%@&extras=%@",FlickrAPIKey,@"cooking",pageNo,(long)perPage,sort,extra]; + + NSLog(@"%@",urlString); + + // Create NSURLSession object + NSURLSession *session = [NSURLSession sharedSession]; + + // Create a NSURL object. + NSURL *url = [NSURL URLWithString:urlString]; + + // Create NSURLSessionDataTask task object by url and session object. + NSURLSessionDataTask *task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + if (!error) { + // NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]); + + // Print response JSON data in the console. + NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]); + + [self->delegate passRequestedArray:[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil] WithId:@"photos_list"]; + + } + }]; + + // Begin task. + [task resume]; + + +} + + +@end diff --git a/codeChallenge/AppDelegate.h b/codeChallenge/AppDelegate.h index ba42db0..40a4144 100644 --- a/codeChallenge/AppDelegate.h +++ b/codeChallenge/AppDelegate.h @@ -7,6 +7,7 @@ // #import +#import "codeChallenge-Swift.h" @interface AppDelegate : UIResponder diff --git a/codeChallenge/Base.lproj/Main.storyboard b/codeChallenge/Base.lproj/Main.storyboard index 8b08874..0f93994 100644 --- a/codeChallenge/Base.lproj/Main.storyboard +++ b/codeChallenge/Base.lproj/Main.storyboard @@ -1,28 +1,81 @@ - - - - + + - + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -32,10 +85,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/codeChallenge/CommonMethods.h b/codeChallenge/CommonMethods.h new file mode 100644 index 0000000..19242a6 --- /dev/null +++ b/codeChallenge/CommonMethods.h @@ -0,0 +1,19 @@ +// +// CommonMethods.h +// codeChallenge +// +// Created by Astha yadav on 05/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface CommonMethods : NSObject + ++ (NSString *)stringByStrippingHTML:(NSString *)inputString; + +@end + +NS_ASSUME_NONNULL_END diff --git a/codeChallenge/CommonMethods.m b/codeChallenge/CommonMethods.m new file mode 100644 index 0000000..95f0fe4 --- /dev/null +++ b/codeChallenge/CommonMethods.m @@ -0,0 +1,35 @@ +// +// CommonMethods.m +// codeChallenge +// +// Created by Astha yadav on 05/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import "CommonMethods.h" + +@implementation CommonMethods + ++ (NSString *)stringByStrippingHTML:(NSString *)inputString +{ + NSMutableString *outString; + + if (inputString) + { + outString = [[NSMutableString alloc] initWithString:inputString]; + + if ([inputString length] > 0) + { + NSRange r; + + while ((r = [outString rangeOfString:@"<[^>]+>| " options:NSRegularExpressionSearch]).location != NSNotFound) + { + [outString deleteCharactersInRange:r]; + } + } + } + + return outString; +} + +@end diff --git a/codeChallenge/CustomCell.m b/codeChallenge/CustomCell.m deleted file mode 100644 index 0e73dd7..0000000 --- a/codeChallenge/CustomCell.m +++ /dev/null @@ -1,22 +0,0 @@ -// -// CustomCell.m -// codeChallenge -// -// Created by Nano Suarez on 18/04/2018. -// Copyright © 2018 Fernando Suárez. All rights reserved. -// - -#import "CustomCell.h" - -@implementation CustomCell - -- (void)awakeFromNib { - [super awakeFromNib]; - // Initialization code - - - self.imageTitleCell.translatesAutoresizingMaskIntoConstraints = YES; -} - - -@end diff --git a/codeChallenge/Info.plist b/codeChallenge/Info.plist index 16be3b6..f41381c 100644 --- a/codeChallenge/Info.plist +++ b/codeChallenge/Info.plist @@ -41,5 +41,10 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + diff --git a/codeChallenge/Modal/PhotosModal.h b/codeChallenge/Modal/PhotosModal.h new file mode 100644 index 0000000..4aabfa9 --- /dev/null +++ b/codeChallenge/Modal/PhotosModal.h @@ -0,0 +1,51 @@ +// +// PhotosModal.h +// codeChallenge +// +// Created by Astha yadav on 03/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface PhotosModal : NSObject + +/* +@property(strong,nonatomic) NSString * photoId; +@property(strong,nonatomic) NSString * owner; +@property(strong,nonatomic) NSString * secret; +@property(strong,nonatomic) NSString * server; +@property(strong,nonatomic) NSString * farm; +@property(strong,nonatomic) NSString * title; +@property(strong,nonatomic) NSString * ispublic; +@property(nonatomic) BOOL * isfriend; +@property(nonatomic) BOOL * isfamily; +@property(strong,nonatomic) NSString * url_t; +@property(nonatomic) NSInteger * height_t; +@property(nonatomic) NSInteger * width_t; + */ + +@property(nonatomic,strong) NSString * title; +@property(nonatomic,strong) NSString * _content; +@property(nonatomic,strong) NSString * url_t; +@property(nonatomic,strong) NSString * url_l; +@property(nonatomic,strong) NSString * ownername; +@property(nonatomic,strong) NSString * dateupload; +@property(nonatomic,strong) NSString * lastupdate; +@property(nonatomic,strong) NSString * datetaken; + + +- (instancetype)initWithJSONString:(NSDictionary *)dict; + +- (nullable NSURL*)imageLogoUrl; +- (nullable NSURL*)imageLargeUrl; + +@end + +NS_ASSUME_NONNULL_END + +/* + {"photos":{"page":1,"pages":44366,"perpage":20,"total":887316,"photo":[{"id":"51221328844","owner":"84904494@N00","secret":"259297038b","server":"65535","farm":66,"title":"scan0001","ispublic":1,"isfriend":0,"isfamily":0,"url_t":"https:\/\/live.staticflickr.com\/65535\/51221328844_259297038b_t.jpg","height_t":82,"width_t":100},{ + */ diff --git a/codeChallenge/Modal/PhotosModal.m b/codeChallenge/Modal/PhotosModal.m new file mode 100644 index 0000000..d3b8872 --- /dev/null +++ b/codeChallenge/Modal/PhotosModal.m @@ -0,0 +1,38 @@ +// +// PhotosModal.m +// codeChallenge +// +// Created by Astha yadav on 03/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import "PhotosModal.h" + +@implementation PhotosModal + +- (instancetype)initWithJSONString:(NSDictionary *)dict; +{ + self = [super init]; + if (self) { + self.title = [dict valueForKey:@"title"]; + self.url_t = [dict valueForKey:@"url_t"]; + self.url_l = [dict valueForKey:@"url_l"]; + self.ownername = [dict valueForKey:@"ownername"]; + self.dateupload = [dict valueForKey:@"dateupload"]; + self.lastupdate = [dict valueForKey:@"lastupdate"]; + self.datetaken = [dict valueForKey:@"datetaken"]; + self._content = [[dict valueForKey:@"description"] valueForKey:@"_content"]; + } + return self; +} + +- (nullable NSURL*)imageLogoUrl { + return [NSURL URLWithString:self.url_t]; +} + +- (nullable NSURL*)imageLargeUrl { + return [NSURL URLWithString:self.url_l]; +} + +@end + diff --git a/codeChallenge/PCH/PrefixHeader.pch b/codeChallenge/PCH/PrefixHeader.pch new file mode 100644 index 0000000..383da34 --- /dev/null +++ b/codeChallenge/PCH/PrefixHeader.pch @@ -0,0 +1,24 @@ +// +// PrefixHeader.pch +// codeChallenge +// +// Created by Astha yadav on 03/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#ifndef PrefixHeader_pch +#define PrefixHeader_pch + +#import "AppDelegate.h" +#import "Constant.h" +#import "PhotosModal.h" +#import "RestClass.h" +#import "CustomCell.h" +#import "ViewController.h" +#import "DetailViewController.h" +#import "codeChallenge-Swift.h" +#import "CommonMethods.h" + + +#endif /* PrefixHeader_pch */ + diff --git a/codeChallenge/ViewController.m b/codeChallenge/ViewController.m deleted file mode 100644 index cf24236..0000000 --- a/codeChallenge/ViewController.m +++ /dev/null @@ -1,122 +0,0 @@ -// -// ViewController.m -// codeChallenge -// -// Created by Nano Suarez on 18/04/2018. -// Copyright © 2018 Fernando Suárez. All rights reserved. -// - -#import "ViewController.h" -#import "CustomCell.h" - -NSString *const FlickrAPIKey = @"2ed35a9f4fda03bc96e73dbd03602780"; - - -@interface ViewController () -@property (nonatomic, readwrite) NSArray *photos; -@property (nonatomic) NSInteger imagePageOffset; -@property (nonatomic, copy) void (^ reloadBlock)(void); - -@end - -@implementation ViewController - -- (void)viewDidLoad { - self.imagePageOffset = 1; - [self loadFlickrPhotos]; - - UINib *cellNib = [UINib nibWithNibName:@"CustomCell" bundle:nil]; - [self.tableView registerNib:cellNib forCellReuseIdentifier:@"CustomCell"]; -} - -- (void)viewWillAppear:(BOOL)animated { - -} - - - -//TableViewDatasource - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.photos.count; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - - static NSString *identifier = @"CustomCell"; - - CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; - - if (cell == nil) { - cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; - } - - - cell.imageTitleCell.text = [[self.photos objectAtIndex:indexPath.row] objectForKey:@"title"]; - cell.imageSubtitleCell.text = [[[self.photos objectAtIndex:indexPath.row] objectForKey:@"description"] objectForKey:@"_content"];; - - - - NSString *urlString = [NSString stringWithFormat:@"https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&tags=%@&per_page=%ld&format=json&nojsoncallback=1&extras=url_t", FlickrAPIKey, @"cooking",(long)self.imagePageOffset]; - - NSURL *url = [NSURL URLWithString:urlString]; - NSURLRequest *request = [NSURLRequest requestWithURL:url]; - NSURLResponse *response = nil; - NSError *error = nil; - NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; - - if (!error) { - - NSDictionary *photos = [[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error] objectForKey:@"photos"]; - NSArray *photo = [photos objectForKey:@"photo"]; - NSString *urlPhotoString = [[photo objectAtIndex:self.imagePageOffset-1] objectForKey:@"url_t"]; - NSURL *urlPhoto = [NSURL URLWithString:urlPhotoString]; - - NSData *imageData = [[NSData alloc] initWithContentsOfURL:urlPhoto]; - UIImage *image = [[UIImage alloc] initWithData:imageData]; - - cell.imageCell.image = image; - self.imagePageOffset += 1; - - self.reloadBlock = ^{ - [self reload]; - }; - - - - dispatch_async(dispatch_get_main_queue(), self.reloadBlock); - } - - -// typedef void(^reloadBlock)() = ^() { -// [self reload]; -// }; - - return cell; -} - -- (void)reload { - [self.tableView reloadData]; -} - -- (void)loadFlickrPhotos { - NSString *urlString = [NSString stringWithFormat:@"https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&tags=%@&per_page=15&format=json&nojsoncallback=1&extras=date_taken,description,tags", FlickrAPIKey, @"cooking"]; - - NSURL *URL = [NSURL URLWithString:urlString]; - NSURLRequest *request = [NSURLRequest requestWithURL:URL]; - NSURLResponse *response = nil; - NSError *error = nil; - - NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; - - if (!error) { - NSDictionary *photosDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; - self.photos = [[photosDictionary objectForKey:@"photos"] objectForKey:@"photo"]; - - dispatch_async(dispatch_get_main_queue(), ^{ - [self.tableView reloadData]; - }); - } -} - -@end diff --git a/codeChallenge/ViewControllers/DetailViewController.h b/codeChallenge/ViewControllers/DetailViewController.h new file mode 100644 index 0000000..c95902b --- /dev/null +++ b/codeChallenge/ViewControllers/DetailViewController.h @@ -0,0 +1,31 @@ +// +// DetailViewController.h +// codeChallenge +// +// Created by Astha yadav on 03/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface DetailViewController : UIViewController +@property (weak, nonatomic) IBOutlet UIScrollView *scrollView; + +@property (weak, nonatomic) IBOutlet UIView *contentView; +@property (weak, nonatomic) IBOutlet UIImageView *imageDetail; +@property (weak, nonatomic) IBOutlet UILabel *labelNoOfViews; +@property (weak, nonatomic) IBOutlet UILabel *labelNoOfFavourite; +@property (weak, nonatomic) IBOutlet UILabel *labelNumberOfComments; +@property (weak, nonatomic) IBOutlet UILabel *labelOwnarName; +@property (weak, nonatomic) IBOutlet UILabel *labelDescription; +@property (weak, nonatomic) IBOutlet UILabel *labelTitle; + +@property(strong,nonatomic)PhotosModal* photoDetail; + + + +@end + +NS_ASSUME_NONNULL_END diff --git a/codeChallenge/ViewControllers/DetailViewController.m b/codeChallenge/ViewControllers/DetailViewController.m new file mode 100644 index 0000000..700b60f --- /dev/null +++ b/codeChallenge/ViewControllers/DetailViewController.m @@ -0,0 +1,60 @@ +// +// DetailViewController.m +// codeChallenge +// +// Created by Astha yadav on 03/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import "DetailViewController.h" + +@interface DetailViewController () + +@end + +@implementation DetailViewController +@synthesize labelTitle,labelOwnarName,labelDescription,labelNoOfViews,labelNoOfFavourite,labelNumberOfComments; +@synthesize photoDetail; + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. + + + + [self setDetailInfo]; +} + +- (void)viewWillAppear:(BOOL)animated{ + [super viewWillAppear:true]; + + NSLog(@"Astha%f",_scrollView.frame.size.height); + // _scrollView.scrollEnabled=YES; + _scrollView.contentSize=CGSizeMake(self.contentView.frame.size.width, 2000); + + NSLog(@"Yadav%f",_scrollView.frame.size.height); + NSLog(@"Yadav%f",_contentView.frame.size.height); +} + +-(void)setDetailInfo{ + + labelOwnarName.text = [NSString stringWithFormat:@"Owner name: %@",photoDetail.ownername]; + labelTitle.text = photoDetail.title; + NSString*strContent = [CommonMethods stringByStrippingHTML:photoDetail._content]; + labelDescription.text = strContent; + + dispatch_async(dispatch_get_global_queue(0,0), ^{ + NSData * data = [[NSData alloc] initWithContentsOfURL: self->photoDetail.imageLargeUrl]; + if ( data == nil ) + return; + dispatch_async(dispatch_get_main_queue(), ^{ + // WARNING: is the cell still using the same data by this point?? + self.imageDetail.image = [UIImage imageWithData: data]; + }); + + }); + +} + + +@end diff --git a/codeChallenge/ViewController.h b/codeChallenge/ViewControllers/ViewController.h similarity index 58% rename from codeChallenge/ViewController.h rename to codeChallenge/ViewControllers/ViewController.h index 9940f82..590bd63 100644 --- a/codeChallenge/ViewController.h +++ b/codeChallenge/ViewControllers/ViewController.h @@ -7,8 +7,12 @@ // @import UIKit; +//@class RestApi; +#import "codeChallenge-Swift.h" @interface ViewController : UITableViewController +@property (weak, nonatomic) IBOutlet UISegmentedControl *segmantControl; +@property (weak, nonatomic) IBOutlet UISwitch *switchLatestOldest; @end diff --git a/codeChallenge/ViewControllers/ViewController.m b/codeChallenge/ViewControllers/ViewController.m new file mode 100644 index 0000000..ad88229 --- /dev/null +++ b/codeChallenge/ViewControllers/ViewController.m @@ -0,0 +1,179 @@ +// +// ViewController.m +// codeChallenge +// +// Created by Nano Suarez on 18/04/2018. +// Copyright © 2018 Fernando Suárez. All rights reserved. +// + +#import "ViewController.h" + + +@interface ViewController (){ + NSMutableArray *photosArray; + NSInteger pageNo,totalPage; + BOOL isFirstLoad; + NSString *sortKey; + RestApi *restapi; +} + +@property (nonatomic, readwrite) NSArray *photos; +@property (nonatomic) NSInteger imagePageOffset; +@property (nonatomic, copy) void (^ reloadBlock)(void); + +@end + +@implementation ViewController + +- (void)viewDidLoad { + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getJSON:) name:@"getJSON" object:nil]; + + restapi = [[RestApi alloc] init]; + photosArray = [NSMutableArray new]; + + [self uiSetUp]; + [self initialData]; + + [self loadFlikerPhotos:pageNo sort:sortKey]; + + +} + +#pragma mark:- initialData +-(void)initialData{ + + self.imagePageOffset = 20; + pageNo = 1; + sortKey = @"date-posted-desc"; + isFirstLoad = YES; +} + +#pragma mark:- uiSetUp +-(void)uiSetUp{ + + [_segmantControl addTarget:self action:@selector(segmentControlClick:) forControlEvents: UIControlEventValueChanged]; + + UINib *cellNib = [UINib nibWithNibName:@"CustomCell" bundle:nil]; + [self.tableView registerNib:cellNib forCellReuseIdentifier:@"CustomCell"]; + +} + +#pragma mark:- loadFlikerPhotos +-(void)loadFlikerPhotos:(NSInteger)pageNo sort:(NSString*)sortKey{ + if (pageNo == 1){ + if ([photosArray count] > 0){ + [photosArray removeAllObjects]; + } + } + [restapi getFlikerPhotosApiWithPageNo:pageNo perPageCount:self.imagePageOffset sort:sortKey]; +} + +#pragma mark:- getJSON +-(void)getJSON:(NSNotification*)notification { + NSDictionary *dict = [notification userInfo]; + NSLog(@"JSON---%@",dict); + NSDictionary * dictPhotos = [dict valueForKey:@"photos"]; + NSArray *arrPhoto = [dictPhotos valueForKey:@"photo"]; + totalPage = [[dictPhotos valueForKey:@"pages"] integerValue]; + pageNo++; + isFirstLoad = NO; + for (int i = 0; i < [arrPhoto count]; i++) { + NSDictionary *json = [arrPhoto objectAtIndex: i]; + PhotosModal* p = [[PhotosModal alloc] initWithJSONString:json]; + [photosArray addObject:p]; + } + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.tableView reloadData]; + }); + +} + +#pragma mark:- switchClick +- (IBAction)switchClick:(id)sender { + +} + +#pragma mark:-segmentControlClick +- (void)segmentControlClick:(UISegmentedControl *)segment +{ + //date-posted-asc, date-posted-desc, date-taken-asc, date-taken-desc, interestingness-desc, interestingness-asc, and relevance. + pageNo = 1; + if(segment.selectedSegmentIndex == 0) + { + sortKey = @"date-posted-desc"; + } + else if(segment.selectedSegmentIndex == 1) + { + sortKey = @"date-taken-desc"; + } + else if(segment.selectedSegmentIndex == 2) + { + sortKey = @"interestingness-desc"; + } + + [self loadFlikerPhotos:pageNo sort:sortKey]; + +} + +#pragma mark:- UITableViewDatasource +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return photosArray.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + static NSString *identifier = @"CustomCell"; + + CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; + if (cell == nil) { + cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; + } + + PhotosModal *objPhoto = [photosArray objectAtIndex:indexPath.row]; + [cell setDisplay:objPhoto]; + + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ + PhotosModal *objPhoto = [photosArray objectAtIndex:indexPath.row]; + DetailViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"]; + vc.photoDetail = objPhoto; + [self.navigationController pushViewController:vc animated:YES]; +} + +- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { + if(indexPath.row == photosArray.count-2) { + if(pageNo <= totalPage && !isFirstLoad) { + [self loadFlikerPhotos:pageNo sort:sortKey]; + } + } +} + +#pragma mark: API Response +-(void)passRequestedArray:(NSMutableArray *)dataArray WithId:(NSString *)ID { + if([ID isEqualToString:@"photos_list"]) { + NSDictionary * dictPhotos = [dataArray valueForKey:@"photos"]; + NSArray *arrPhoto = [dictPhotos valueForKey:@"photo"]; + totalPage = [[dictPhotos valueForKey:@"pages"] integerValue]; + pageNo++; + isFirstLoad = NO; + for (int i = 0; i < [arrPhoto count]; i++) { + NSDictionary *json = [arrPhoto objectAtIndex: i]; + PhotosModal* p = [[PhotosModal alloc] initWithJSONString:json]; + [photosArray addObject:p]; + } + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.tableView reloadData]; + }); + } +} + +-(void)errorMessageWithRetry:(NSString *)errorMsg WithId:(NSString *)ID { + +} + +@end diff --git a/codeChallenge/CustomCell.h b/codeChallenge/Views/CustomCell.h similarity index 88% rename from codeChallenge/CustomCell.h rename to codeChallenge/Views/CustomCell.h index ead38ec..f72df40 100644 --- a/codeChallenge/CustomCell.h +++ b/codeChallenge/Views/CustomCell.h @@ -13,4 +13,7 @@ @property (weak, nonatomic) IBOutlet UILabel *imageTitleCell; @property (weak, nonatomic) IBOutlet UILabel *imageSubtitleCell; + +- (void)setDisplay:(nullable PhotosModal *)display; + @end diff --git a/codeChallenge/Views/CustomCell.m b/codeChallenge/Views/CustomCell.m new file mode 100644 index 0000000..f3760d3 --- /dev/null +++ b/codeChallenge/Views/CustomCell.m @@ -0,0 +1,39 @@ +// +// CustomCell.m +// codeChallenge +// +// Created by Nano Suarez on 18/04/2018. +// Copyright © 2018 Fernando Suárez. All rights reserved. +// + +#import "CustomCell.h" + +@implementation CustomCell + +- (void)awakeFromNib { + [super awakeFromNib]; + +} + +- (void)setDisplay:(nullable PhotosModal *)display { + + [self.imageTitleCell setText:display.title]; + NSString*strContent = [CommonMethods stringByStrippingHTML:display._content]; + [self.imageSubtitleCell setText:strContent]; + + dispatch_async(dispatch_get_global_queue(0,0), ^{ + NSData * data = [[NSData alloc] initWithContentsOfURL: display.imageLogoUrl]; + if ( data == nil ) + return; + dispatch_async(dispatch_get_main_queue(), ^{ + // WARNING: is the cell still using the same data by this point?? + self.imageCell.image = [UIImage imageWithData: data]; + }); + + }); + + // TODO load image + [self.imageCell setBackgroundColor:UIColor.blueColor]; +} + +@end diff --git a/codeChallenge/CustomCell.xib b/codeChallenge/Views/CustomCell.xib similarity index 72% rename from codeChallenge/CustomCell.xib rename to codeChallenge/Views/CustomCell.xib index e2c4c85..5ad9d70 100644 --- a/codeChallenge/CustomCell.xib +++ b/codeChallenge/Views/CustomCell.xib @@ -1,11 +1,9 @@ - - - - + + - + @@ -13,54 +11,54 @@ - - + + - + - + - - + - + + + - + + - + + diff --git a/codeChallenge/codeChallenge-Bridging-Header.h b/codeChallenge/codeChallenge-Bridging-Header.h new file mode 100644 index 0000000..1b2cb5d --- /dev/null +++ b/codeChallenge/codeChallenge-Bridging-Header.h @@ -0,0 +1,4 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + From b8df3e1b342951d6957ba9df9b135462a4318e56 Mon Sep 17 00:00:00 2001 From: astha-iOS Date: Mon, 7 Jun 2021 09:50:13 +0530 Subject: [PATCH 2/3] added scroll on detail page --- RestApiUnitTests/RestApiUnitTests.m | 37 +++++ codeChallenge.xcodeproj/project.pbxproj | 152 ++++++++++++++++-- .../xcdebugger/Breakpoints_v2.xcbkptlist | 18 +-- .../xcschemes/xcschememanagement.plist | 8 + codeChallenge/ApiManager/RestApi.swift | 21 +-- codeChallenge/ApiManager/RestClass.h | 31 ---- codeChallenge/ApiManager/RestClass.m | 59 ------- codeChallenge/Base.lproj/Main.storyboard | 81 ++++------ codeChallenge/{ => Common}/CommonMethods.h | 2 + codeChallenge/{ => Common}/CommonMethods.m | 18 +++ .../{ApiManager => Common}/Constant.h | 4 +- codeChallenge/Modal/PhotosModal.h | 20 +-- codeChallenge/Modal/PhotosModal.m | 2 + codeChallenge/PCH/PrefixHeader.pch | 1 - .../ViewControllers/DetailViewController.h | 6 - .../ViewControllers/DetailViewController.m | 20 +-- .../ViewControllers/ViewController.m | 55 +++---- codeChallenge/Views/CustomCell.xib | 4 +- 18 files changed, 286 insertions(+), 253 deletions(-) create mode 100644 RestApiUnitTests/RestApiUnitTests.m delete mode 100644 codeChallenge/ApiManager/RestClass.h delete mode 100644 codeChallenge/ApiManager/RestClass.m rename codeChallenge/{ => Common}/CommonMethods.h (79%) rename codeChallenge/{ => Common}/CommonMethods.m (54%) rename codeChallenge/{ApiManager => Common}/Constant.h (54%) diff --git a/RestApiUnitTests/RestApiUnitTests.m b/RestApiUnitTests/RestApiUnitTests.m new file mode 100644 index 0000000..d490ad4 --- /dev/null +++ b/RestApiUnitTests/RestApiUnitTests.m @@ -0,0 +1,37 @@ +// +// RestApiUnitTests.m +// codeChallengeTests +// +// Created by Astha yadav on 06/06/21. +// Copyright © 2021 Fernando Suárez. All rights reserved. +// + +#import + +@interface RestApiUnitTests : XCTestCase + +@end + +@implementation RestApiUnitTests + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +- (void)testExample { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. +} + +- (void)testPerformanceExample { + // This is an example of a performance test case. + [self measureBlock:^{ + // Put the code you want to measure the time of here. + }]; +} + +@end diff --git a/codeChallenge.xcodeproj/project.pbxproj b/codeChallenge.xcodeproj/project.pbxproj index 324cf91..715948c 100644 --- a/codeChallenge.xcodeproj/project.pbxproj +++ b/codeChallenge.xcodeproj/project.pbxproj @@ -10,9 +10,9 @@ 0745256A266A3BA800342E43 /* RestApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07452569266A3BA800342E43 /* RestApi.swift */; }; 074C69BE266B40E700E82DBE /* CommonMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = 074C69BD266B40E700E82DBE /* CommonMethods.m */; }; 074C69C1266B568500E82DBE /* .gitignore in Resources */ = {isa = PBXBuildFile; fileRef = 074C69C0266B568500E82DBE /* .gitignore */; }; - 0759896926689BA0002129B1 /* RestClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 0759896826689BA0002129B1 /* RestClass.m */; }; 075989722668A309002129B1 /* PhotosModal.m in Sources */ = {isa = PBXBuildFile; fileRef = 075989712668A309002129B1 /* PhotosModal.m */; }; 0764840C2668EDEB00022B6F /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0764840B2668EDEB00022B6F /* DetailViewController.m */; }; + 07FAA8F6266D307400C1AB05 /* RestApiUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 07FAA8F5266D307400C1AB05 /* RestApiUnitTests.m */; }; 3E15BBE4208754FE0029597E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E15BBE3208754FE0029597E /* AppDelegate.m */; }; 3E15BBE7208754FE0029597E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E15BBE6208754FE0029597E /* ViewController.m */; }; 3E15BBEA208754FE0029597E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E15BBE8208754FE0029597E /* Main.storyboard */; }; @@ -23,20 +23,30 @@ 3E15BBFC20879B4B0029597E /* CustomCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3E15BBFB20879B4B0029597E /* CustomCell.xib */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 075273E9266CDB5000AF8AD7 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 3E15BBD7208754FE0029597E /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3E15BBDE208754FE0029597E; + remoteInfo = codeChallenge; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXFileReference section */ 07452568266A3BA800342E43 /* codeChallenge-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "codeChallenge-Bridging-Header.h"; sourceTree = ""; }; 07452569266A3BA800342E43 /* RestApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestApi.swift; sourceTree = ""; }; 074C69BC266B40E700E82DBE /* CommonMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommonMethods.h; sourceTree = ""; }; 074C69BD266B40E700E82DBE /* CommonMethods.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CommonMethods.m; sourceTree = ""; }; 074C69C0266B568500E82DBE /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = ""; }; - 0759896726689BA0002129B1 /* RestClass.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RestClass.h; sourceTree = ""; }; - 0759896826689BA0002129B1 /* RestClass.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RestClass.m; sourceTree = ""; }; + 075273E4266CDB5000AF8AD7 /* codeChallengeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = codeChallengeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0759896B26689E22002129B1 /* Constant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Constant.h; sourceTree = ""; }; 075989702668A309002129B1 /* PhotosModal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PhotosModal.h; sourceTree = ""; }; 075989712668A309002129B1 /* PhotosModal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PhotosModal.m; sourceTree = ""; }; 076484072668C31600022B6F /* PrefixHeader.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrefixHeader.pch; sourceTree = ""; }; 0764840A2668EDEB00022B6F /* DetailViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DetailViewController.h; sourceTree = ""; }; 0764840B2668EDEB00022B6F /* DetailViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DetailViewController.m; sourceTree = ""; }; + 07FAA8F5266D307400C1AB05 /* RestApiUnitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RestApiUnitTests.m; sourceTree = ""; }; 3E15BBDF208754FE0029597E /* codeChallenge.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = codeChallenge.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3E15BBE2208754FE0029597E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 3E15BBE3208754FE0029597E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -53,6 +63,13 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 075273E1266CDB5000AF8AD7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 3E15BBDC208754FE0029597E /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -63,12 +80,19 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 0759896626689B3B002129B1 /* ApiManager */ = { + 074C69C4266B73C800E82DBE /* Common */ = { isa = PBXGroup; children = ( 0759896B26689E22002129B1 /* Constant.h */, - 0759896726689BA0002129B1 /* RestClass.h */, - 0759896826689BA0002129B1 /* RestClass.m */, + 074C69BC266B40E700E82DBE /* CommonMethods.h */, + 074C69BD266B40E700E82DBE /* CommonMethods.m */, + ); + path = Common; + sourceTree = ""; + }; + 0759896626689B3B002129B1 /* ApiManager */ = { + isa = PBXGroup; + children = ( 07452569266A3BA800342E43 /* RestApi.swift */, ); path = ApiManager; @@ -112,9 +136,18 @@ path = PCH; sourceTree = ""; }; + 07FAA8F9266D308D00C1AB05 /* RestApiUnitTests */ = { + isa = PBXGroup; + children = ( + 07FAA8F5266D307400C1AB05 /* RestApiUnitTests.m */, + ); + path = RestApiUnitTests; + sourceTree = ""; + }; 3E15BBD6208754FE0029597E = { isa = PBXGroup; children = ( + 07FAA8F9266D308D00C1AB05 /* RestApiUnitTests */, 074C69C0266B568500E82DBE /* .gitignore */, 3E15BBE1208754FE0029597E /* codeChallenge */, 3E15BBE0208754FE0029597E /* Products */, @@ -125,6 +158,7 @@ isa = PBXGroup; children = ( 3E15BBDF208754FE0029597E /* codeChallenge.app */, + 075273E4266CDB5000AF8AD7 /* codeChallengeTests.xctest */, ); name = Products; sourceTree = ""; @@ -132,6 +166,7 @@ 3E15BBE1208754FE0029597E /* codeChallenge */ = { isa = PBXGroup; children = ( + 074C69C4266B73C800E82DBE /* Common */, 076484062668C30A00022B6F /* PCH */, 0759896F2668A1B1002129B1 /* Modal */, 0759896626689B3B002129B1 /* ApiManager */, @@ -145,8 +180,6 @@ 3E15BBF0208754FE0029597E /* Info.plist */, 3E15BBF1208754FE0029597E /* main.m */, 07452568266A3BA800342E43 /* codeChallenge-Bridging-Header.h */, - 074C69BC266B40E700E82DBE /* CommonMethods.h */, - 074C69BD266B40E700E82DBE /* CommonMethods.m */, ); path = codeChallenge; sourceTree = ""; @@ -154,6 +187,24 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 075273E3266CDB5000AF8AD7 /* codeChallengeTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 075273EB266CDB5000AF8AD7 /* Build configuration list for PBXNativeTarget "codeChallengeTests" */; + buildPhases = ( + 075273E0266CDB5000AF8AD7 /* Sources */, + 075273E1266CDB5000AF8AD7 /* Frameworks */, + 075273E2266CDB5000AF8AD7 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 075273EA266CDB5000AF8AD7 /* PBXTargetDependency */, + ); + name = codeChallengeTests; + productName = codeChallengeTests; + productReference = 075273E4266CDB5000AF8AD7 /* codeChallengeTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; 3E15BBDE208754FE0029597E /* codeChallenge */ = { isa = PBXNativeTarget; buildConfigurationList = 3E15BBF5208754FE0029597E /* Build configuration list for PBXNativeTarget "codeChallenge" */; @@ -180,6 +231,10 @@ LastUpgradeCheck = 0930; ORGANIZATIONNAME = "Fernando Suárez"; TargetAttributes = { + 075273E3266CDB5000AF8AD7 = { + CreatedOnToolsVersion = 12.1; + TestTargetID = 3E15BBDE208754FE0029597E; + }; 3E15BBDE208754FE0029597E = { CreatedOnToolsVersion = 9.3; LastSwiftMigration = 1210; @@ -200,11 +255,19 @@ projectRoot = ""; targets = ( 3E15BBDE208754FE0029597E /* codeChallenge */, + 075273E3266CDB5000AF8AD7 /* codeChallengeTests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 075273E2266CDB5000AF8AD7 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 3E15BBDD208754FE0029597E /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -220,6 +283,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 075273E0266CDB5000AF8AD7 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 07FAA8F6266D307400C1AB05 /* RestApiUnitTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 3E15BBDB208754FE0029597E /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -227,7 +298,6 @@ 0745256A266A3BA800342E43 /* RestApi.swift in Sources */, 074C69BE266B40E700E82DBE /* CommonMethods.m in Sources */, 075989722668A309002129B1 /* PhotosModal.m in Sources */, - 0759896926689BA0002129B1 /* RestClass.m in Sources */, 3E15BBE7208754FE0029597E /* ViewController.m in Sources */, 3E15BBF2208754FE0029597E /* main.m in Sources */, 3E15BBFA208774B10029597E /* CustomCell.m in Sources */, @@ -238,6 +308,14 @@ }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 075273EA266CDB5000AF8AD7 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3E15BBDE208754FE0029597E /* codeChallenge */; + targetProxy = 075273E9266CDB5000AF8AD7 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ 3E15BBE8208754FE0029597E /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -258,6 +336,53 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 075273EC266CDB5000AF8AD7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = UXY7GXJWTF; + INFOPLIST_FILE = ""; + IPHONEOS_DEPLOYMENT_TARGET = 14.1; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = ASTHA.codeChallengeTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/codeChallenge.app/codeChallenge"; + }; + name = Debug; + }; + 075273ED266CDB5000AF8AD7 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = UXY7GXJWTF; + INFOPLIST_FILE = ""; + IPHONEOS_DEPLOYMENT_TARGET = 14.1; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = ASTHA.codeChallengeTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/codeChallenge.app/codeChallenge"; + }; + name = Release; + }; 3E15BBF3208754FE0029597E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -420,6 +545,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 075273EB266CDB5000AF8AD7 /* Build configuration list for PBXNativeTarget "codeChallengeTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 075273EC266CDB5000AF8AD7 /* Debug */, + 075273ED266CDB5000AF8AD7 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 3E15BBDA208754FE0029597E /* Build configuration list for PBXProject "codeChallenge" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 166464a..083823e 100644 --- a/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -7,7 +7,7 @@ - - - - diff --git a/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcschemes/xcschememanagement.plist b/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcschemes/xcschememanagement.plist index 35598e5..3023e5a 100644 --- a/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/codeChallenge.xcodeproj/xcuserdata/asthayadav.xcuserdatad/xcschemes/xcschememanagement.plist @@ -10,5 +10,13 @@ 0 + SuppressBuildableAutocreation + + 3E15BBDE208754FE0029597E + + primary + + + diff --git a/codeChallenge/ApiManager/RestApi.swift b/codeChallenge/ApiManager/RestApi.swift index 13ec414..f9c7e44 100644 --- a/codeChallenge/ApiManager/RestApi.swift +++ b/codeChallenge/ApiManager/RestApi.swift @@ -8,6 +8,7 @@ import Foundation import UIKit +import Contacts class RestApi : NSObject { @@ -17,22 +18,24 @@ class RestApi : NSObject { } @objc func getFlikerPhotosApi(pageNo:Int,perPageCount:Int,sort:String){ - let extra = "date_taken,views,description,date_upload,date_taken,owner_name,icon_server,original_format,last_update,views,media,url_t,url_l" - let BASEURL = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&tags=%@&page=%ld&per_page=%ld&format=json&nojsoncallback=1&sort=%@&extras=%@" - - let urlString : String = String(format:BASEURL,"2ed35a9f4fda03bc96e73dbd03602780","cooking",pageNo,perPageCount,sort,extra) - + + let extra = "date_taken,views,description,date_upload,date_taken,owner_name,icon_server,original_format,last_update,views,media,url_t,url_l" + let FLICKR_APIKEY = "2ed35a9f4fda03bc96e73dbd03602780" + let tags = "cooking" + let BASEURL = "https://api.flickr.com/services/rest/" + let requestParams = String(format: "method=flickr.photos.search&api_key=%@&tags=%@&page=%ld&per_page=%ld&format=json&nojsoncallback=1&sort=%@&extras=%@", FLICKR_APIKEY,tags,pageNo,perPageCount,sort,extra) + + let completeUrlString = String(format: "%@?%@", BASEURL,requestParams) + + print(completeUrlString) let session = URLSession.shared - - guard let url = URL(string: urlString) else { return } - + guard let url = URL(string: completeUrlString) else { return } let task = session.dataTask(with: url, completionHandler: { data, response, error in if error == nil { do { if let jsonData = data { let json = try JSONSerialization.jsonObject(with: jsonData, options: []) as! [String: Any] - // print(json) NotificationCenter.default.post(name: NSNotification.Name(rawValue: "getJSON"), object: self, userInfo: json) } } catch { diff --git a/codeChallenge/ApiManager/RestClass.h b/codeChallenge/ApiManager/RestClass.h deleted file mode 100644 index aeb3fad..0000000 --- a/codeChallenge/ApiManager/RestClass.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// RestClass.h -// codeChallenge -// -// Created by Astha yadav on 03/06/21. -// Copyright © 2021 Fernando Suárez. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@protocol APIDelegates - -@optional --(void)passRequestedArray:(NSMutableArray*)dataArray WithId:(NSString*)ID; --(void)errorMessageWithRetry:(NSString*)errorMsg WithId:(NSString*)ID; -@end - -@interface RestClass : NSObject - -@property (nonatomic, weak) id delegate; - --(id)initWithDelegate:(id)del; - -#pragma mark:flickr Api --(void)getFlickrPhotoApi:(NSInteger)perPage withPageNumber:(NSInteger)pageNo sortBy:(NSString*)sort; - -@end - -NS_ASSUME_NONNULL_END diff --git a/codeChallenge/ApiManager/RestClass.m b/codeChallenge/ApiManager/RestClass.m deleted file mode 100644 index c6bf860..0000000 --- a/codeChallenge/ApiManager/RestClass.m +++ /dev/null @@ -1,59 +0,0 @@ -// -// RestClass.m -// codeChallenge -// -// Created by Astha yadav on 03/06/21. -// Copyright © 2021 Fernando Suárez. All rights reserved. -// - -#import "RestClass.h" - -@implementation RestClass - -@synthesize delegate; - -- (id)initWithDelegate:(id )del -{ - self = [super init]; - - if (!self) - return nil; - [self setDelegate:del]; - return self; -} - -#pragma mark: flickr Api --(void)getFlickrPhotoApi:(NSInteger)perPage withPageNumber:(NSInteger)pageNo sortBy:(NSString*)sort{ - NSString *extra = @"date_taken,views,description,date_upload,date_taken,owner_name,icon_server,original_format,last_update,views,media,url_t,url_l"; - - NSString *urlString = [NSString stringWithFormat:@"https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&tags=%@&page=%ld&per_page=%ld&format=json&nojsoncallback=1&sort=%@&extras=%@",FlickrAPIKey,@"cooking",pageNo,(long)perPage,sort,extra]; - - NSLog(@"%@",urlString); - - // Create NSURLSession object - NSURLSession *session = [NSURLSession sharedSession]; - - // Create a NSURL object. - NSURL *url = [NSURL URLWithString:urlString]; - - // Create NSURLSessionDataTask task object by url and session object. - NSURLSessionDataTask *task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { - if (!error) { - // NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]); - - // Print response JSON data in the console. - NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]); - - [self->delegate passRequestedArray:[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil] WithId:@"photos_list"]; - - } - }]; - - // Begin task. - [task resume]; - - -} - - -@end diff --git a/codeChallenge/Base.lproj/Main.storyboard b/codeChallenge/Base.lproj/Main.storyboard index 0f93994..ad6cc68 100644 --- a/codeChallenge/Base.lproj/Main.storyboard +++ b/codeChallenge/Base.lproj/Main.storyboard @@ -28,9 +28,9 @@ - - - + + +