Wednesday 30 October 2013

How to install maven on Mac OSX 10.9 (mavericks)

I just updated to the fresh OSX 10.9 and found that a few things are not there, these things include “maven” too. So you can install Maven with package manager.
That Package Manager is Homebrew.


Homebrew website   http://brew.sh/


Install Homebrew if you don’t have it in your system


Just apply the following command:


Then install Maven using this package manager.


Run this command on your terminal:


$ brew install maven


After completing the download just confirm that your maven is successfully installed, run the command:


$ maven -version


If you get the following output, it means maven is installed successfully.


 Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 20:52:22+0530)  
 Maven home: /usr/local/Cellar/maven/3.1.1/libexec  
 Java version: 1.6.0_65, vendor: Apple Inc.  
 Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home  
 Default locale: en_US, platform encoding: MacRoman  
 OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"  

Share if you find it worthy. Enjoy Coding..!!!

Trick: NSLog without date time stamp, application name, and process id info.

In my previous post, I have discussed that how to create a custom log But today I am going to discuss a new trick that how to hide  date time stamp, application name, and process id info, when you are going to print your information through NSLogs.

The NSLogs original output is 

2013-10-28 14:58:04.816 MyProject[17368:70b] Hi my new Message

But you can modify it to more simple way:

(-[Sample viewDidLoad]) (Sample.m:33) Hi my new Message

Isn't it a cool wat to show your logs without any timeStamp, No process ID. You can also implement this as it is very simple. Just follow the steps below:


Step 1: Create a Constant.h file in your project. First Right click on your project name

NoteIf you already have a Constants.h file or any other file in which you are storing your constants then skip this step and just write the below code there, else follow the step 2



then Select C/C++ under iOS section and Select a header file.


Then Name it as Constants.h and Add this file to your project.

Step 2: Now open the Constants.h file and write the following code there: 

 #define NSLog(args...) CustomLog(__FILE__, __LINE__, __PRETTY_FUNCTION__, args)  
 static inline void CustomLog(const char *file, int lineNumber, const char *functionName, NSString *format, ...)  
 {  
   // Type to hold information about variable arguments.  
   va_list ap;  
   // Initialize a variable argument list.  
   va_start (ap, format);  
   // NSLog only adds a newline to the end of the NSLog format if  
   // one is not already there.  
   // Here we are utilizing this feature of NSLog()  
   if (![format hasSuffix: @"\n"])  
   {  
     format = [format stringByAppendingString: @"\n"];  
   }  
   NSString *body = [[NSString alloc] initWithFormat:format arguments:ap];  
   // End using variable argument list.  
   va_end (ap);  
   NSString *fileName = [[NSString stringWithUTF8String:file] lastPathComponent];  
   fprintf(stderr, "(%s) (%s:%d) %s",  
       functionName, [fileName UTF8String],  
       lineNumber, [body UTF8String]);  
 }  

Step 3 : After adding this code in Constants.h file, open the Prefix.pch file in your project . You can find it in Supporting Files group in Project navigator.

 #ifdef __OBJC__  
   #import <UIKit/UIKit.h>  
   #import <Foundation/Foundation.h>  
   #import "Constants.h"  
 #endif  

By adding this file here you do not have need to import this file in every file.

All set now. What you have to do is to implement the new NSLog method and there it is your new logs without timestamps and processIds..!!

Share if you find it worthful.. enjoy coding..!!!


Monday 28 October 2013

Tutorial: How to customize NSLog for detailed information during debugging.

We can get the detailed information of each method while execution. since it is very helpful in debugging the crash all over the application. Also you can verify the data your are passing or save is same as you want.

Customization of NSLog is very simple. Just follow these below steps and get customize logs.

You can get information about File name, Line No., Message Name, and many more variables.
Just follow the simple steps below:


in Prefix.pch file, <you can find this file in Supporting Files group>.


add the following code:

#define LogEnable 1     //   0  ==> Disable, 1  ==> Enable

 // If you set the value to 1 it means customLog will apperar on the debug window 
Always set one for Debug Mode you can set it 1 on debug mode  using this code snippet:

 #ifdef DEBUG
    #define LogEnable 1
#else
    #define LogEnable 0

 #define DebugLog(__FORMAT__, ...) { if (LogEnable) NSLog((@"%@ %s %d " __FORMAT__), [[NSString stringWithUTF8String: __FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}

Now try it on any Method in a file


like I am trying it on Sample.m file in checkingCustomLog method at line number 10:

//
//  Sample.m.m
//  MyProject
//
//  Created by Sahil Mahajan on 9/13/13.
//  Copyright (c) 2013 Sahil Mahajan. All rights reserved.
//

 #import "Sample.h"

 @implementation Sample

 -(void) checkingCustomLog
{
    DebugLog(@”Got a custom log”);
}


And the output is like:

2013-10-28 14:58:04.816 MyProject[17368:70b] Sample.m -[Sample checkingCustomLog] 15 Got a custom log

Sunday 27 October 2013

Tutorial : How to search a specific string pattern in library files or .a files in your project.

In this post I would like to give you some information about How to search a string pattern in a library file or .a file that you included in your project. Many times we faced this situation when we need to check the library files' content. Similar problem I faced during my validation of project before submitting my app to Apple Apps Store. My application didn't pass the validation test as some of my libraries contain deprecated APIs. When I search for that API in my project in xcode search, I didn't find any class that uses that API.
I was also using some 3rd party libraries in my project like PayPal integration and some more. so after a lot of research, I analysed that the problem may be in 3rd party library but how to search the content of library and confirmed that which library is using the deprecated API was a difficult task. But I search it and finally I came to know the solution which I am going to share it with you.

First step: Open your command line and go to directory where the project is located using command:

cd ~/YOUR_PROJECT_DIRECTORY

Second step: Now search for the 3rd party library files that you are using in your projects using command: 

find . -name "*.a" -print 

Last step: Now if you want to search a specific string pattern in that libraries, use the following command: 

find . | grep "\.a" | grep -v "\.app" | xargs grep “Your Specific String” 

In my project, the paypal library.a is using deprecated API "uniqueIdentifier" and when I updated that library everything's working fine.

Please share this post if you find it worthy and useful. Happy coding..!!!

Get LOC (Lines of code) for your project in Xcode/ Mac

Sometimes We need to calculate the total lines of code in our project. so I came to know that there is a very good and efficient tool for calculating it using your system. That tool is called as CLOC aka Count Lines of Code. It supports many languages like c, c++, java, perl, scripiting, xml, objective-C and many more.

Now take a look on how to install cloc.

Things need to be downloaded:

Download CLOC from the link : Download CLOC

After downloading the ./cloc-1.60.pl' perm version of cloc tool, enable the executable permissions on the cloc tool by following command:

chmod u+x cloc-1.60.pl

Now note the directory path of your project and apply the following command:

./cloc-1.58.pl ~“Your Project Directory path”

voila..!! Your every detailed information about the projects file is on the screen.
cloc counts blank lines, comment lines, and physical lines of source code.

Also if you want to know the languages it supports then goto CLOC recoganized languages

for more details visit the website CLOC Website.

Share it if you find it helpful and worthy..!!

Happy coding..!!

Welcome Novice in the world of iPhone App Development.

Welcome to the iPhone Applications Development World.


This blog is for the novice iPhone Developers who just start their carrier with the hot and most popular mobile technology of the world. I ll keep all of you updated with the new upcoming features that will help you to build your application with new and advanced features. So all you need is knowledge of Xcode (IDE for development) and Objective-C (programming language for developing apps). In my blog, I ll provide you the material to learn tips and tricks for iPhone app development. So Lets Start..!!!!