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

CocoaHeadsNL Februari - Presentation about a Cocoa wrapper on re framework - Berend Schotanus

CocoaHeadsNL Februari - Presentation about a Cocoa wrapper on re framework - Berend Schotanus

Presentation given by Berend Schotanus on a re cocoa wrapper. Great wrapper around a great routing algorithm.

CocoaHeadsNL

February 18, 2015
Tweet

More Decks by CocoaHeadsNL

Other Decks in Programming

Transcript

  1. Who is Berend Schotanus? 1984 - 1990 Delft University of

    Technology,
 Civil Engineering - Transportation 1990’s Transport & Urban planning for Dutch Railways 2000’s Railway signaling and traffic management 2010’s Software development + mobility speciality Concept development:
 relation humans - society - technology
  2. The task • C framework • Large chunk of code

    • I’m not really experienced in C… ★ Can I use it on iOS? ➔ Building a bridge ★ What’s going on inside? ➔ Bindings
  3. Approach • Figure out the data structure • Create obj-C

    objects representing the structure • Connect “bridging” objects • Treat C code as opaque “dataContext”
  4. OVDataController static tdata_t _ctx; @implementation OVDataController + (instancetype)sharedInstance { <-

    Standard implementation here -> return _sharedInstance; } - (instancetype)init { if (self = [super init]) { NSURL *dataURL = [[NSBundle mainBundle] URLForResource:@"timetable" withExtension:@“dat"]; tdata_load(&_ctx, (char *)[[dataURL path] cStringUsingEncoding: [NSString defaultCStringEncoding]]); } return self; }
  5. OVObject @interface OVObject : NSObject - initWithIndex:(int32_t)index; @property (nonatomic, readonly)

    OVDataController *dataController; @property (nonatomic, readonly) tdata_t *ctx; @property (nonatomic, assign) int32_t index; @end @implementation OVObject - (id)initWithIndex:(int32_t)index { <- Standard implementation here -> return self; } - (OVDataController *)dataController { return [OVDataController sharedInstance]; } - (tdata_t *)ctx { return self.dataController.dataContext; }
  6. OVAgency @implementation OVAgency - (NSString *)name { return [[NSString alloc]

    initWithUTF8String: tdata_agency_name_for_index(self.ctx, self.index)]; }
  7. Bindings • “reduces code dependencies”
 “eliminates glue code” • Based

    on Key-Value Observing • Connect your UI to its data from Interface Builder • Like Filemaker or Microsoft Access