Skip to main content


Showing posts from 2017

Return multiple values from a function in objective C

We can return tuples in swift as follows:- func getData () -> ( Int , Int , Int ) { //...code here return ( hour , minute , second ) } You can't do that in objective-c. Best option is using parameters by reference . Something like this. - ( void ) getHour :( int *) hour minute :( int *) minute second :( int *) second { * hour = 1 ; * minute = 2 ; * second = 3 ; } And use it like this. int a , b , c ; [ self getHour :& a minute :& b second :& c ]; NSLog (@ "%i, %i, %i" , a , b , c );

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); } //***

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 he

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 bit Windows 64 bit Mac OS X Linux UNIX

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 = @"" ;          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 = [ NSString stringWithFormat :embedHTML, url, self . view . frame . siz

Working with MongoDB

Generate a new SSH key ( ). If you have already ssh key generated at mac, then copy the key using:- pbcopy < ~/.ssh/ Pass the key to your server developer (DevOps). He will give access to a server, for eg: When he add your key, then open the terminal and type command:- ssh root@ You will see this in terminal:-   The authenticity of host ' (' can't be established. RSA key fingerprint is SHA256:supbA7wsdvc3xXnVyHvj7fXGjlpCpt1kigJrljR4. Are you sure you want to continue connecting (yes/no)? Enter yes Enter your server addresss ( in your browser and it connects and start working. Mongo official reference for queries:-