Skip to content

Latest commit

 

History

History
351 lines (286 loc) · 14.7 KB

README.md

File metadata and controls

351 lines (286 loc) · 14.7 KB

LaneKit

Gem Version

LaneKit is an iOS Objective-C code generator for integration with RestKit. It generates models, resource providers, table views, and full iOS apps with mimimal effort. There is support for unit testing with XCTest including fixtures and tests. LaneKit is a command line app written in Ruby and packaged as a Ruby Gem.

Benefits

  • properly implemented models, resource providers, and table views
  • easy integration with RestKit
  • consistent Objective-C code
  • unit tests with XCTest
  • test fixtures in JSON and Objective-C
  • iOS app creation fully integrated with CocoaPods and RestKit, and .gitignore file
  • tested code
  • rapid development
  • enhanced productivity of junior developers
  • reduces dependency on senior developers

How To Get Started

  1. Install the LaneKit Ruby Gem from RubyGems.org on the command line:

     $ gem install lanekit
     Successfully installed lanekit-0.9.0
     $ lanekit -v
     LaneKit 0.9.0
    
  2. LaneKit is ready to use.

Example Usage

Add a new model called Video to an existing Xcode project:

$ lanekit generate model Video headline:string duration:string id:integer image:string itemDate:date location:string

  create  SportsFrames/SportsFrames/Models
  create  SportsFrames/SportsFramesTests/Fixtures
  create  SportsFrames/SportsFramesTests/Models
  create  SportsFrames/SportsFramesTests/Resources
  create  SportsFrames/SportsFrames/Models/Video.h
  create  SportsFrames/SportsFrames/Models/Video.m
  create  SportsFrames/SportsFramesTests/Fixtures/VideoFixtures.h
  create  SportsFrames/SportsFramesTests/Fixtures/VideoFixtures.m
  create  SportsFrames/SportsFramesTests/Resources/VideoFixtures.one.json
  create  SportsFrames/SportsFramesTests/Resources/VideoFixtures.two.json
  create  SportsFrames/SportsFramesTests/Models/VideoTest.h
  create  SportsFrames/SportsFramesTests/Models/VideoTest.m
  create  SportsFrames/SportsFrames/Models/LKModel.h
  create  SportsFrames/SportsFrames/Models/LKModel.m

and here is the Objective-C header file that was generated by LaneKit:

//
//  Video.h
//
//  LaneKit is available under the MIT license. See the LICENSE file for more info.
//
//  This model was created on 2014-01-11 by LaneKit v0.4.4.
//
// The following LaneKit command was used to generate this file:
// lanekit generate model Video headline:string duration:string id:integer image:string itemDate:date location:string
//

#import "LKModel.h"

@interface Video : LKModel

@property (nonatomic,strong) NSString *headline;
@property (nonatomic,strong) NSString *duration;
@property (nonatomic,strong) NSNumber *id;
@property (nonatomic,strong) NSString *image;
@property (nonatomic,strong) NSDate *itemDate;
@property (nonatomic,strong) NSString *location;

@end

and here is the Objective-C .m file that was generated by LaneKit:

//
//  Video.m
//
//  LaneKit is available under the MIT license. See the LICENSE file for more info.
//
//  This model was created on 2014-01-11 by LaneKit v0.4.4.
//
// The following LaneKit command was used to generate this file:
// lanekit generate model Video headline:string duration:string id:integer image:string itemDate:date location:string
//

#import "Video.h"

@implementation Video

#pragma mark LKModel overrides

// Dictionary to convert self to JSON/XML. For XML mappings, add .text to the end of the destination attribute name like this: "title.text".
+ (NSDictionary *)dictionaryForRequestMappings
{
    return @{
             // source key path : destination attribute name
             @"headline": @"headline",
             @"duration": @"duration",
             @"id": @"id",
             @"image": @"image",
             @"itemDate": @"itemDate",
             @"location": @"location"
    };
}

// Dictionary to convert JSON/XML to self. For XML mappings, add .text to the end of the key path like this: "title.text".
+ (NSDictionary *)dictionaryForResponseMappings
{
  return @{
           // source key path : destination attribute name
             @"headline": @"headline",
             @"duration": @"duration",
             @"id": @"id",
             @"image": @"image",
             @"itemDate": @"itemDate",
             @"location": @"location"
    };
}

+ (NSString *)keyPath
{
  return @"video";
}

- (NSString *)descriptionForDisplay
{
  return [NSString stringWithFormat:@"%@", self.headline];
}

@end

and here is the unit test fixtures file that was generated by LaneKit:

//
//  VideoFixtures.m
//
//  LaneKit is available under the MIT license. See the LICENSE file for more info.
//
//  This model fixture was created on 2014-01-11 by LaneKit v0.4.4.
//
// The following LaneKit command was used to generate this file:
// lanekit generate model Video headline:string duration:string id:integer image:string itemDate:date location:string
//

#import "VideoFixtures.h"

@implementation VideoFixtures

+ (Video *)one
{
  Video *video = Video.new;

  video.headline = @"MyString";
  video.duration = @"MyString";
  video.id = [NSNumber numberWithInteger:1];
  video.image = @"MyString";
  video.itemDate = NSDate.new;
  video.location = @"MyString";

  return video;
}

+ (Video *)two
{
  Video *video = Video.new;

  video.headline = @"MyString";
  video.duration = @"MyString";
  video.id = [NSNumber numberWithInteger:1];
  video.image = @"MyString";
  video.itemDate = NSDate.new;
  video.location = @"MyString";

  return video;
}

@end

and here is a RestKit compatible JSON fixture file that was generated by LaneKit:

{
  "video": {
    "headline": "MyString",
    "duration": "MyString",
    "id": "1",
    "image": "MyString",
    "itemDate": "03/01/2012",
    "location": "MyString"
  }
}

and here is part of a unit test that was generated in Models/VideoTest.m by LaneKit:

- (void)testVideoNewOne
{
  Video *video = VideoFixtures.one;
  XCTAssertNotNil(video, @"video is nil");

  XCTAssertTrue([video.headline isEqualToString:@"MyString"], @"headline not correct value");
  XCTAssertTrue([video.duration isEqualToString:@"MyString"], @"duration not correct value");
  XCTAssertTrue(video.id.integerValue == [NSNumber numberWithInteger:1].integerValue, @"id not [NSNumber numberWithInteger:1]");
  XCTAssertTrue([video.image isEqualToString:@"MyString"], @"image not correct value");
  XCTAssertNotNil(video.itemDate, @"itemDate is nil");
  XCTAssertTrue([video.location isEqualToString:@"MyString"], @"location not correct value");
}

- (void)testVideoNewTwo
{
  Video *video = VideoFixtures.two;
  XCTAssertNotNil(video, @"video is nil");

  XCTAssertTrue([video.headline isEqualToString:@"MyString"], @"headline not correct value");
  XCTAssertTrue([video.duration isEqualToString:@"MyString"], @"duration not correct value");
  XCTAssertTrue(video.id.integerValue == [NSNumber numberWithInteger:1].integerValue, @"id not [NSNumber numberWithInteger:1]");
  XCTAssertTrue([video.image isEqualToString:@"MyString"], @"image not correct value");
  XCTAssertNotNil(video.itemDate, @"itemDate is nil");
  XCTAssertTrue([video.location isEqualToString:@"MyString"], @"location not correct value");
}

- (void)testMapping
{
  RKObjectMapping *requestMapping = [Video requestMapping];
  XCTAssertNotNil(requestMapping, @"[Video requestMapping] returned nil.");
  
  RKObjectMapping *responseMapping = [Video responseMapping];
  XCTAssertNotNil(responseMapping, @"[Video responseMapping] returned nil.");
}

Add a new model called Contents that contains a list of Videos and uses a relationship mapping.

$ lanekit generate model contents contents:array:Video
 exist  Classes/model
create  Classes/model/Contents.h
create  Classes/model/Contents.m

Add a new resource provider called Contents.

$ lanekit generate provider Contents Contents http://scores.espn.go.com/allsports/scorecenter/v2/videos/build?sport=top
create  Classes/Controllers
create  Classes/Controllers/LKResourceProvider.h
create  Classes/Controllers/LKResourceProvider.m
create  Classes/Controllers/ContentsProvider.h
create  Classes/Controllers/ContentsProvider.m

Create a new iOS app fully integrated with CocoaPods and RestKit.

$ lanekit new SportsFrames
create  SportsFrames
create  SportsFrames/Podfile
create  SportsFrames/lanekit-ios-project.xcworkspace/contents.xcworkspacedata
create  SportsFrames/lanekit-ios-project.xcworkspace/xcshareddata/lanekit-ios-project.xccheckout
create  SportsFrames/lanekit-ios-project.xcworkspace/xcuserdata/larry.xcuserdatad/UserInterfaceState.xcuserstate
create  SportsFrames/lanekit-ios-project/lanekit-ios-project.xcodeproj/project.pbxproj
create  SportsFrames/lanekit-ios-project/lanekit-ios-project.xcodeproj/project.xcworkspace/contents.xcworkspacedata
create  SportsFrames/lanekit-ios-project/lanekit-ios-project.xcodeproj/xcuserdata/larry.xcuserdatad/xcschemes/lanekit-ios-project.xcscheme
create  SportsFrames/lanekit-ios-project/lanekit-ios-project.xcodeproj/xcuserdata/larry.xcuserdatad/xcschemes/xcschememanagement.plist
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Controllers/LKAppDelegate.h
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Controllers/LKAppDelegate.m
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Controllers/LKDetailViewController.h
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Controllers/LKDetailViewController.m
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Controllers/LKMasterViewController.h
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Controllers/LKMasterViewController.m
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Resources/Base.lproj/Main_iPad.storyboard
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Resources/Base.lproj/Main_iPhone.storyboard
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Resources/Images.xcassets/AppIcon.appiconset/Contents.json
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Resources/Images.xcassets/LaunchImage.launchimage/Contents.json
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Resources/en.lproj/InfoPlist.strings
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Supporting Files/lanekit-ios-project-Info.plist
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Supporting Files/lanekit-ios-project-Prefix.pch
create  SportsFrames/lanekit-ios-project/lanekit-ios-project/Supporting Files/main.m
create  SportsFrames/lanekit-ios-project/lanekit-ios-projectTests/en.lproj/InfoPlist.strings
create  SportsFrames/lanekit-ios-project/lanekit-ios-projectTests/lanekit-ios-projectTests-Info.plist
create  SportsFrames/lanekit-ios-project/lanekit-ios-projectTests/lanekit-ios-projectTests.m
create  SportsFrames/.gitignore
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames/Supporting Files/SportsFrames-Info.plist
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames/Supporting Files/SportsFrames-Prefix.pch
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames.xcodeproj
update  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames.xcodeproj/project.pbxproj
update  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames.xcodeproj/project.xcworkspace/contents.xcworkspacedata
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames.xcodeproj/xcuserdata/larry.xcuserdatad/xcschemes/SportsFrames.xcscheme
update  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames.xcodeproj/xcuserdata/larry.xcuserdatad/xcschemes/SportsFrames.xcscheme
update  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFrames.xcodeproj/xcuserdata/larry.xcuserdatad/xcschemes/xcschememanagement.plist
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFramesTests
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFramesTests/SportsFramesTests-Info.plist
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames/SportsFramesTests/SportsFramesTests.m
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames.xcworkspace
update  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames.xcworkspace/contents.xcworkspacedata
rename  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames.xcworkspace/xcshareddata/SportsFrames.xccheckout
update  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames.xcworkspace/xcshareddata/SportsFrames.xccheckout
update  /Users/larry/Projects/lanekit/SportsFrames/Podfile
Installing CocoaPods for RestKit
[in /Users/larry/Projects/lanekit/SportsFrames]
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (1.3.3)
Installing RestKit (0.20.3)
Installing SOCKit (1.1)
Installing TransitionKit (1.1.1)
Generating Pods project
Integrating client project
clean  /Users/larry/Projects/lanekit/SportsFrames/SportsFrames.xcworkspace

Add a new UITableViewController called ContentsViewController

This will display the Contents model that is a list of videos.

$ lanekit generate tableviewcontroller Contents -r LKFeedCell

create  SportsFrames/SportsFrames/Controllers/ContentsViewController.h
create  SportsFrames/SportsFrames/Controllers/ContentsViewController.m
create  SportsFrames/SportsFrames/Views/LKFeedCell.h
create  SportsFrames/SportsFrames/Views/LKFeedCell.m

Add the Urban Airship CocoaPods Pod to the project.

$ lanekit generate pod UrbanAirship-iOS-SDK

Installing UrbanAirship-iOS-SDK (3.0.1)

Sample App

The SportsFrames app is a fully functional iOS sample app using RestKit created to demonstrate the use of LaneKit in a real world app. It has models and resource providers that are generated from LaneKit. Download the code from GitHub.

Credits

LaneKit was created by Larry Aasen. Follow Larry Aasen on Twitter @LarryAasen.

License

LaneKit is available under the MIT license. See the LICENSE file for more info.