Skip to content

Instantly share code, notes, and snippets.

@ShaharHD
Last active August 29, 2015 14:03
Show Gist options
  • Save ShaharHD/ed4b064924d1ee350578 to your computer and use it in GitHub Desktop.
Save ShaharHD/ed4b064924d1ee350578 to your computer and use it in GitHub Desktop.
Keen.IO comments
  1. "sqlite3.h", "sqlite3.c" & “sqlite3ext.h” filename should all have the prefix of “keen_io” as the latter are version ambiguous.
  2. “KIOEventStore.h" should import "keen_io_sqlite3.h” and not “sqlite3.h” which is ambiguous.
  3. The distribution zip (cocoa pods or not) should include the "keen_io_sqlite3.h” as it is imported by “KIOEventStore.h"
  4. The usage of NSDateFormatter is not thread-safe (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html). A better and much faster solution would be (as you have sqlite now) to simply execute something like:
sqlite3_stmt *statement = NULL;
sqlite3_prepare_v2(db, "SELECT datetime('now');", -1, &statement, NULL);    
sqlite3_bind_text(statement, 1, format, -1, SQLITE_STATIC);
sqlite3_step(statement);

char *value = (char *)sqlite3_column_text(statement, 0);
NSString *string;
   
if (value) {
   string = [NSString stringWithUTF8String:value];
}

Which is thread safe - as you can have a memory file sqlite connection open as SQLITE_CONFIG_MULTITHREAD (just for the date formatting) because no data is written or read from that connection (that’s how we do it in our app). sqlite3_open(":memory:", &db); Or you can just open and close it on every request if you wish.

  1. The library log version print is problematic, as [KeenClient isLoggingEnabled] will only be set or relevant after the init (as we, the end users, are probably using shared instance). A better solution IMHO would be to have it print on every set (if its enabled) and also to allow the user the ability to read the kKeenSdkVersion as a class method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment