Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DO NOT REPEAT YOURSELF

DO NOT REPEAT YOURSELF

Leverage the power of C++ and Djinni to write native cross platform code on iOS and Android

90f7f6e0fe6a8b894481158315b1de07?s=128

Marco Sero

March 13, 2015
Tweet

More Decks by Marco Sero

Other Decks in Programming

Transcript

  1. DO NOT REPEAT YOURSELF

  2. IOS AND ANDROID HAVE SOMETHING IN COMMON

  3. C++

  4. BUT USING IT... IT'S NOT GREAT

  5. Objective-C++ on iOS JNI (Java Native Interface) on Android

  6. UNTIL...

  7. DJINNI BY

  8. .djinni interface + C++ implementation Djinni JAVA AND OBJECTIVE-C INTERFACES

  9. THE HACK

  10. SHARED C++ IMAGE CACHE

  11. DEFINE INTERFACE IN A .djinni FILE image_cache = interface +c

    { static create_with_path(path: string): image_cache; image_for_key(key: string): binary; save_image_for_key(key: string, image_data: binary); }
  12. IMPLEMENT IT IN C++ shared_ptr<ImageCache> ImageCache::create_with_path(const std::string &path) { ...

    } vector<uint8_t> ImageCache::image_for_key(const string &key) { ... } void ImageCache::save_image_for_key(const string &key, const vector<uint8_t> &image_data) { ... }
  13. USE IT FROM OBJECTIVE-C id<YCCPImageCache> imageCache = [YCPPImageCacheCppProxy createWithPath:cachePath]; NSData

    *imageData = [imageCache imageForKey:cacheKey]; [imageCache saveImageForKey:cacheKey imageData:imageData]; AND JAVA ImageCache imageCache = ImageCache.createWithPath(cachePath); byte[] imageBlob = this.imageCache.imageForKey(cacheKey); imageCache.saveImageForKey(cacheKey, imageBlob);
  14. NEVER WRITE JNI AND OBJECTIVE-C++ AGAIN

  15. SHARE NATIVE CODE BETWEEN PLATFORMS MORE EASILY

  16. DO I RECOMMEND THIS?

  17. NO AT LEAST FOR OUR APPS

  18. THANK YOU.