2014年6月22日星期日

Parse framework on Cocoa (OSX)

Got this error when running the empty project after imported Parse SDK.

"dyld: Library not loaded: @executable_path/../Frameworks/ParseOSX.framework/ParseOSX Referenced from: /Users.......Reason: image not found"

And here is the answer: https://parse.com/questions/parse-framework-not-working-in-cocoa


  1. Add a Copy Files Build Phase (Editor -> Add Build Phase -> Add Copy Files Build Phase)
  2. Then set the destination to Products Directory.
  3. Then click on the + button to choose the Parse Framework.
Seems a useful technique to deal with missing library or linking problem.

2013年1月29日星期二

Windows Phone 8 emulater in VMWare

Add these three lines to the vmx file of the virtual machine:

hypervisor.cpuid.v0 = FALSE
vhv.enable = TRUE

mce.enable = TRUE

Settings -> CPU and memory -> Advanced: checked "Enable hypervisor applications in this  virtual machine"

Settings -> CPU and memory: make sure 2 Cores (or more?) are assigned to the Virutla machine
Settings -> Advanced: Preferred virtualizationn engine: Intel VT-x with EPT


VMWare Documentation
Reference

2013年1月3日星期四

Lua on C++

I am adding Lua script support in my C++ project targeted on iOS. There are errors when building on simulator.

Undefined symbols for architecture i386:
    "lua_gettop(lua_State*)", referenced from:
    "lua_resume(lua_State*, lua_State*, int)", referenced from:
...
..
.
To solve it, add "extern "C" " symbol to the include keywords to lua headers.

#ifdef __cplusplus
extern "C" {
#include "lua.h"
}
#endif


Reference: StackOverFlow

2012年12月21日星期五

C++ Check File Exists

Check whether a file exists:


#include <sys/stat.h>
// Function: fileExists
/**
    Check if a file exists
@param[in] filename - the name of the file to check

@return    true if the file exists, else false

*/
bool fileExists(const std::string& filename)
{
    struct stat buf;
    if (stat(filename.c_str(), &buf) != -1)
    {
        return true;
    }
    return false;
}

Not sure whether it works on all platforms.

Source:StackOverFlow

C++ Split String

Making some cross-platform stuffs and shifted back to C++ recently.
Trying to do something like NSString's componentsSeparatedByString function in C++.

/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="- This, a sample string.";
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str," ,.-");
  while (pch != NULL)
  {
    printf ("%s\n",pch);
    pch = strtok (NULL, " ,.-");
  }
  return 0;
}


in the while loop, add those string into an array and return it back can do similiar job.

ref:cpluscplus.com

2012年7月24日星期二

"UPSERT " - Update or Insert in Sqlite

"INSERT OR REPLACE" is NOT equal to "UPDATE IF EXIST ,ELSE INSERT"
Since REPLACE is actually and "delete + create" action, not update.
Users need to insert values for ALL columns.

This thread on StackOverFlow provided a better solution to this issue.

Using UPDATE OR REPLACE together with SELECT and coalesce is an alternative to it.