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

The Great GAXB

The Great GAXB

Meet the great GAXB, your latest open source best friend. Code more of what you want, less of what you don't.

Brooklyn iOS Meetup - 04/16/2014

Quinn McHenry

April 16, 2014
Tweet

More Decks by Quinn McHenry

Other Decks in Programming

Transcript

  1. The Great GAXB Quinn McHenry Senior Developer ! ! !

    ! @qmchenry [email protected] ! ! @smallplanetapps github.com/smallplanet/gaxb speakerdeck.com/qmchenry/the-great-gaxb
  2. XML Binding XML ObjC java template c++ template ??? template

    .cpp .h .java .? ObjC template GAXB executable .m .h
  3. Generic Architecture java template c++ template ??? template .cpp .h

    .java .? ObjC template GAXB executable .m .h
  4. Compile time Runtime Information → Code Information 㲗 Objects +

    (id) readFromFile:(NSString *)path;! ! + (id) readFromData:(NSData *)data;! ! + (id) readFromString:(NSString *)xml_string;! ! + (void) write:(id)object toFile:(NSString *)path;! ! + (NSData *) writeToData:(id)object;! ! + (NSString *) writeToString:(id)object; GAXB + = XSD .m .h .m .h .m .h .m .h .m .h .m .h
  5. Information → Code @interface Galaxy_AstronomicalObjectBase : NSObject! ! @property (nonatomic,

    retain) NSString * name;! @property (nonatomic,readonly) BOOL nameExists;! @property (nonatomic) float mass;! @property (nonatomic,readonly) BOOL massExists;! @property (nonatomic) float meanOrbitalDistance;! @property (nonatomic,readonly) BOOL meanOrbitalDistanc ! ! - (NSString *) nameAsString;! - (void) setNameWithString:(NSString *)string;! - (NSString *) massAsString;! - (void) setMassWithString:(NSString *)string;! - (NSString *) meanOrbitalDistanceAsString;! - (void) setMeanOrbitalDistanceWithString:(NSString *) <!-- Astronomical Object -->! ! <element name="AstronomicalObject" type="ga:AstronomicalObject"/>! ! <complexType name="AstronomicalObject">! ! ! <attribute name="name" type="string" use="required"/>! ! ! <attribute name="mass" type="float" use="optional"/>! ! ! <attribute name="meanOrbitalDistance" type="float" use="optional"/>! ! </complexType>! ! ! <!-- Solar System -->! ! <element name="StarSystem" type="ga:StarSystem"/>! ! <complexType name="StarSystem">! ! ! <sequence>! ! ! ! <element ref="ga:AstronomicalObject" minOccurs="0" maxOccurs="! ! ! ! <element ref="ga:Star" minOccurs="1" maxOccurs="unbounded"/>! ! ! ! <element ref="ga:Planet" minOccurs="0" maxOccurs="unbounded"/>! ! ! </sequence>! ! ! <attribute name="name" type="string" use="required"/>! ! </complexType>! ! ! <!-- Star -->! ! <element name="Star" type="ga:Star"/>! ! <complexType name="Star">! ! ! <complexContent>! ! ! ! <extension base="ga:AstronomicalObject">! ! ! ! ! <attribute name="age" type="float" use="optional"/> XML Schema GAXB Generated Code
  6. Information → Code @interface Galaxy_AstronomicalObjectBase : NSObject! ! @property (nonatomic,

    retain) NSString * name;! @property (nonatomic,readonly) BOOL nameExists;! @property (nonatomic) float mass;! @property (nonatomic,readonly) BOOL massExists;! @property (nonatomic) float meanOrbitalDistance;! @property (nonatomic,readonly) BOOL meanOrbitalDistanc ! ! - (NSString *) nameAsString;! - (void) setNameWithString:(NSString *)string;! - (NSString *) massAsString;! - (void) setMassWithString:(NSString *)string;! - (NSString *) meanOrbitalDistanceAsString;! - (void) setMeanOrbitalDistanceWithString:(NSString *) <!-- Astronomical Object -->! ! <element name="AstronomicalObject" type="ga:AstronomicalObject"/>! ! <complexType name="AstronomicalObject">! ! ! <attribute name="name" type="string" use="required"/>! ! ! <attribute name="mass" type="float" use="optional"/>! ! ! <attribute name="meanOrbitalDistance" type="float" use="optional"/>! ! </complexType>! ! ! <!-- Solar System -->! ! <element name="StarSystem" type="ga:StarSystem"/>! ! <complexType name="StarSystem">! ! ! <sequence>! ! ! ! <element ref="ga:AstronomicalObject" minOccurs="0" maxOccurs="! ! ! ! <element ref="ga:Star" minOccurs="1" maxOccurs="unbounded"/>! ! ! ! <element ref="ga:Planet" minOccurs="0" maxOccurs="unbounded"/>! ! ! </sequence>! ! ! <attribute name="name" type="string" use="required"/>! ! </complexType>! ! ! <!-- Star -->! ! <element name="Star" type="ga:Star"/>! ! <complexType name="Star">! ! ! <complexContent>! ! ! ! <extension base="ga:AstronomicalObject">! ! ! ! ! <attribute name="age" type="float" use="optional"/> XML Schema GAXB Generated Code
  7. Information → Code @interface Galaxy_AstronomicalObjectBase : NSObject! ! @property (nonatomic,

    retain) NSString * name;! @property (nonatomic,readonly) BOOL nameExists;! @property (nonatomic) float mass;! @property (nonatomic,readonly) BOOL massExists;! @property (nonatomic) float meanOrbitalDistance;! @property (nonatomic,readonly) BOOL meanOrbitalDistanc ! ! - (NSString *) nameAsString;! - (void) setNameWithString:(NSString *)string;! - (NSString *) massAsString;! - (void) setMassWithString:(NSString *)string;! - (NSString *) meanOrbitalDistanceAsString;! - (void) setMeanOrbitalDistanceWithString:(NSString *) <!-- Astronomical Object -->! ! <element name="AstronomicalObject" type="ga:AstronomicalObject"/>! ! <complexType name="AstronomicalObject">! ! ! <attribute name="name" type="string" use="required"/>! ! ! <attribute name="mass" type="float" use="optional"/>! ! ! <attribute name="meanOrbitalDistance" type="float" use="optional"/>! ! </complexType>! ! ! <!-- Solar System -->! ! <element name="StarSystem" type="ga:StarSystem"/>! ! <complexType name="StarSystem">! ! ! <sequence>! ! ! ! <element ref="ga:AstronomicalObject" minOccurs="0" maxOccurs="! ! ! ! <element ref="ga:Star" minOccurs="1" maxOccurs="unbounded"/>! ! ! ! <element ref="ga:Planet" minOccurs="0" maxOccurs="unbounded"/>! ! ! </sequence>! ! ! <attribute name="name" type="string" use="required"/>! ! </complexType>! ! ! <!-- Star -->! ! <element name="Star" type="ga:Star"/>! ! <complexType name="Star">! ! ! <complexContent>! ! ! ! <extension base="ga:AstronomicalObject">! ! ! ! ! <attribute name="age" type="float" use="optional"/> XML Schema GAXB Generated Code
  8. Information 㲗 Objects <?xml version="1.0" encoding="utf-8" ?>! <StarSystem xmlns="http://schema.smallplanet.com/Galaxy" name="Solar

    System">! ! ! <!-- Sol -->! ! <Star name="Sol" age="4570000" mass="3330000"/>! ! ! <!-- Sol's Planets -->! ! <Planet name="Mercury" mass="0.055" equatorialRadius="0.3825"/>! ! <Planet name="Venus" mass="0.815" equatorialRadius="0.9488"/>! ! <Planet name="Earth" mass="1" equatorialRadius="1">! ! ! <Moon name="Moon" mass="0.0123" equatorialRadius="0.273"/>! ! </Planet>! ! <Planet name="Mars" mass="0.107" equatorialRadius="0.53226"/>! ! <Planet name="Jupiter" mass="318" equatorialRadius=“11.209" hasRings="true" >! ! ! <Moon name="Io"/>! ! ! <Moon name="Europa"/>! ! ! <Moon name="Ganymede"/>! ! ! <Moon name="Callisto"/>! ! </Planet>! ! <Planet name="Saturn" mass="95" equatorialRadius=“9.449" ! !! ! ! ...
  9. Information 㲗 Objects <?xml version="1.0" encoding="utf-8" ?>! <StarSystem xmlns="http://schema.smallplanet.com/Galaxy" name="Solar

    System">! ! ! <!-- Sol -->! ! <Star name="Sol" age="4570000" mass="3330000"/>! ! ! <!-- Sol's Planets -->! ! <Planet name="Mercury" mass="0.055" equatorialRadius="0.3825"/>! ! <Planet name="Venus" mass="0.815" equatorialRadius="0.9488"/>! ! <Planet name="Earth" mass="1" equatorialRadius="1">! ! ! <Moon name="Moon" mass="0.0123" equatorialRadius="0.273"/>! ! </Planet>! ! <Planet name="Mars" mass="0.107" equatorialRadius="0.53226"/>! ! <Planet name="Jupiter" mass="318" equatorialRadius=“11.209" hasRings="true" >! ! ! <Moon name="Io"/>! ! ! <Moon name="Europa"/>! ! ! <Moon name="Ganymede"/>! ! ! <Moon name="Callisto"/>! ! </Planet>! ! <Planet name="Saturn" mass="95" equatorialRadius=“9.449" ! !! ! ! ...
  10. <?xml version="1.0" encoding="utf-8" ?>! <Scene bounds="fullScreen">! ! <Image bounds="parent" filepath="menu_background.png"/>!

    ! ! ! <Button bounds=“191,174,70,68"! ! ! ! iconNormal="btn_credits.png" ! ! ! ! onTouchUp="launch_credits"/>! ! <Button bounds="119,129,70,68" ! ! ! ! iconNormal="btn_dragonpaint.png" ! ! ! ! onTouchUp="launch_paint"/>! ! ! ! <Label bounds="333,158,80,50" text="READ" ! ! ! ! font="NiftyScroll-Heavy" fontSize="38" ! ! ! ! textColor="white">! ! ! ! ! ! <Button bounds="parent" ! ! ! ! ! ! ! ! ! onTouchUp="launch_book"/>! ! </Label>! </Scene>
  11. <?xml version="1.0" encoding="utf-8" ?>! <Scene bounds="fullScreen">! ! <Image bounds="parent" filepath="menu_background.png"/>!

    ! ! ! <Button bounds=“191,174,70,68"! ! ! ! iconNormal="btn_credits.png" ! ! ! ! onTouchUp="launch_credits"/>! ! <Button bounds="119,129,70,68" ! ! ! ! iconNormal="btn_dragonpaint.png" ! ! ! ! onTouchUp="launch_paint"/>! ! ! ! <Label bounds="333,158,80,50" text="READ" ! ! ! ! font="NiftyScroll-Heavy" fontSize="38" ! ! ! ! textColor="white">! ! ! ! ! ! <Button bounds="parent" ! ! ! ! ! ! ! ! ! onTouchUp="launch_book"/>! ! </Label>! </Scene>
  12. <?xml version="1.0" encoding="utf-8" ?>! <Scene bounds="fullScreen">! ! <Image bounds="parent" filepath="menu_background.png"/>!

    ! ! ! <Button bounds=“191,174,70,68"! ! ! ! iconNormal="btn_credits.png" ! ! ! ! onTouchUp="launch_credits"/>! ! <Button bounds="119,129,70,68" ! ! ! ! iconNormal="btn_dragonpaint.png" ! ! ! ! onTouchUp="launch_paint"/>! ! ! ! <Label bounds="333,158,80,50" text="READ" ! ! ! ! font="NiftyScroll-Heavy" fontSize="38" ! ! ! ! textColor="white">! ! ! ! ! ! <Button bounds="parent" ! ! ! ! ! ! ! ! ! onTouchUp="launch_book"/>! ! </Label>! </Scene>
  13. <?xml version="1.0" encoding="utf-8" ?>! <Scene bounds="fullScreen">! ! <Image bounds="parent" filepath="menu_background.png"/>!

    ! ! ! <Button bounds=“191,174,70,68"! ! ! ! iconNormal="btn_credits.png" ! ! ! ! onTouchUp="launch_credits"/>! ! <Button bounds="119,129,70,68" ! ! ! ! iconNormal="btn_dragonpaint.png" ! ! ! ! onTouchUp="launch_paint"/>! ! ! ! <Label bounds="333,158,80,50" text="READ" ! ! ! ! font="NiftyScroll-Heavy" fontSize="38" ! ! ! ! textColor="white">! ! ! ! ! ! <Button bounds="parent" ! ! ! ! ! ! ! ! ! onTouchUp="launch_book"/>! ! </Label>! </Scene> ! <Label bounds="333,158,80,50" text="READ" ! ! ! ! font="NiftyScroll-Heavy" fontSize="38" ! ! ! ! textColor="white">! ! ! ! ! ! <Button bounds="parent" ! ! ! ! ! ! ! ! ! onTouchUp="launch_book"/>! ! </Label> UILabel *label = [[UILabel alloc] init];! label.frame = CGRectMake(333, 158, 80, 50);! label.text = @"READ";! label.font = [UIFont fontWithName:! ! ! ! ! @"NiftyScroll-Heavy" size:38];! label.textColor = [UIColor whiteColor];! UIButton *button = [[UIButton alloc] init];! button.frame = label.bounds;! [button addTarget:self !! ! ! ! ! ! action:@selector(launchBook:)! forControlEvents:UIControlEventTouchUpInside];! [label addSubview:button];! [self.view addSubview:label];
  14. Why ❤️ GAXB? Don’t code the same thing twice Spend

    more time coding the cool stuff Peaceful coexistence