Posts

Understanding MVP

Image
We all are using MVC in the beginning because it is easy, but MVP architecture is not that difficult to understand and implement in iOS project. Currently, I am using the MVP architecture in my latest project and I come to know many advantages of it.

To begin with, the most preponderant advantage of using MVC is that it is scalable. The second significant advantage which is worth mentioning is that if you have different flavours of your application where business logic (presenter) is same, then MVC is the right choice.

A good example here is:-

MVP folder structure consist of model, view, protocols, presenter, xib, service classes.




Model class consist of all the properties which hold the dataView class consist of all the UI elements which are visible to user. Separate xib for each viewProtocol class consist of methods which need to implement by view class and presenter classPresenter class consist of business logicService class consist of api interaction methods
Flow: Assign the custom vi…

Test cases code coverage in Xcode

How to check what percentage of unit test cases cover your classes/framework/project:- After writing unit test cases, make sure your all test cases run successfully. To cross check this, Goto Product menu->Perform action-> Test without buildingGoto Edit scheme: Select Test and select the "Gather coverage data" option.To see the code coverage, perform step no 1 once again.Open the last tab(report navigator) on the left panel.Open the coverage tab(at the top panel)

Return multiple values from a function in objective C

We can return tuples in swift as follows:-

func getData()->(Int,Int,Int){//...code herereturn( hour, minute, second)}You can't do that in objective-c. Best option is using parameters by reference.

Calling depending Web Services + dispatch_group_t in iOS

What is the best approach to call the web services in a chain?

Create a dispatch group

dispatch_group_t serviceGroup;
Call the first function/web service
-(void)callFirstWebService { serviceGroup = dispatch_group_create();
//Call 1st web service here, In the completion block, call the second method which you want to perform serially [self callSecondWebService];

dispatch_group_notify(serviceGroup,dispatch_get_main_queue(),^{ // Won't get here until everything has finished NSLog(@"All Tasks finished"); //Reload table or another task which you want to perform when both service finished }); }

-(void) callSecondWebService{ dispatch_group_enter(serviceGroup); //Call 2nd web service and in the completion block, write the below code
dispatch_group_leave(serviceGroup); }

//*******************Theoretical Explantion*****************
Create a method where you want to call webservice. Depending on response, you want to call another webservice/method. After completion of all task, you want to perform las…

Semaphore | Delay splash screen in iOS + Objective C

How to wait for an asynchronously dispatched block to finish?How to integrate semaphore in iOS?How to delay splash screen for longer time, so that developer can prefetch or execute something before start of iOS App.
The answer of all the above questions is SEMAPHORE.  A semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system such as a multiprogramming operating system. 
Suppose you want to perform some task before root view controller is shown to user.  Goto AppDelegate's method didFinishLaunchingWithOptions, create a method as below:- 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     [self performTaskToDelaySplash]; }
-(void) performTaskToDelaySplash {     dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); //1. Create semaphore //Perform your task here, i.e Any webservice call or any database operation
         dispatch_semaphore_signa…

MySQL connect utility in Mac OS

Using DbVisualizer, we can connect to MySQL database on Mac.
Download the installer (select appropriate Platform & Installer Type) here
DbVisualizer offers setup for following platforms:-
Windows 32 bitWindows 64 bitMac OS XLinuxUNIX

Play youtube video in iOS app

Youtube video can be played in iOS app using webview. MPMoviePlayerController is not able to open youtube video automatically. Integrate the below script to show thumbnail, clicking on it the video will play in full screen.


NSString *url = @"https://www.youtube.com/embed/8aMHGC6A5zc"; NSString* embedHTML = @"\     <html><head>\     <style type=\"text/css\">\     body {\     background-color: transparent;\     color: white;\     }\     </style>\     </head><body style=\"margin:0\">\     <iframe id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \     width=\"%0.0f\" height=\"%0.0f\" frameborder=\"0\" feature=player_detailpage allowfullscreen></iframe>\     </body></html>"; NSString* html = [NSStringstringWithFormat:embedHTML, url, self.view.frame.size.width, 200.0];
    [webviewloadHTMLString:html baseURL:nil];


///*******************A…