Wednesday, July 30, 2014

iOS define local and global NSString constant

situee.blogspot.com

1. Local Constant

There are two type of constants.

(1)  static NSString * const kMyConstant = @"constant string";

(2)  #define kMyConstant @"constant string"


"static const" is a better way, although "#define" is much shorter,

Here are some reasons:

  • "#define" are not type-safe. 
  • We can test the value of the "static const" constant with debugger;
  • Memory. Preprocessor create a new string each time the macro appear, while "static const" reuse the same string.

2. Global Constant

----------------  .h file  --------------

extern NSString *const kMyConstant;

----------------  .m file  --------------
// define in a .m file OUTSIDE @implementation like...

NSString *const kMyConstant = @"my constant";

The extern declaration says that there exists an NSString * const by the name kMyConstant whose storage is created in some other place.[1]

Remove the static -- that specifies that kMyConstant is only visible in files linked with this one.[1]

C pointer and constant

Review C pointer and constant:
situee.blogspot.com

1. Pointer to Constant Value

const char *ptr = 'a';  OR    char const *ptr = 'a'

"const" precedes the *, that means the pointer treat *ptr  as constant

This is NOT valid     :  
*ptr = 'b';

Another example;

int nValue = 5;
const int *pnPtr = &nValue;

Thus, the following is okay:
    nValue = 6; // nValue is non-const
But the following is not:
    *pnPtr = 6; // pnPtr treats its value as const


2. Constant Pointer

char * const ptr = 'a';

This means the pointer ptr is a constant pointer

This is NOT valid:
char char_B = 'b';
ptr = &char_B;


3. Constant Pointer to Constant Value

const char * const ptr = 'a';  OR    char const * const ptr = 'a';


Reference:


http://www.learncpp.com/cpp-tutorial/610-pointers-and-const/
http://www.cprogramming.com/reference/pointers/const_pointers.html
http://www.noxeos.com/2011/07/29/c-const-static-keywords/
http://www.codeguru.com/cpp/cpp/cpp_mfc/general/article.php/c6967/Constant-Pointers-and-Pointers-to-Constants.htm

Sunday, July 20, 2014

Android - SuppressLint cannot be resolved to a type

After upgrading my Android SDK 20 and ADT-23.0.2, some projects got error "SuppressLint cannot be resolved to a type"



I fixed this by

1. In project property -> Android, change to another API level and change back.
2. change the order in project property ->Java build path -> Order and Export.
3. also please try refresh and clean the project.

Hope it can help and save some hours.

Tuesday, July 08, 2014

OpenDrive cloud storage direct link

I am trying OpenDrive storage service.
You will get 5G storage, and 1G traffic for a basic account.
It is great that you can share file by direct link.
I think it is very useful for a developer.
We can put XML, JSON, image files on the OpenDrive for testing.

Go to their website and have a look:
www.opendrive.com