Giter Site home page Giter Site logo

insanoid / swiftyjsonaccelerator Goto Github PK

View Code? Open in Web Editor NEW
944.0 40.0 121.0 4.48 MB

macOS app to generate Swift 5 code for models from JSON (with Codeable)

License: MIT License

Swift 98.54% Ruby 0.27% Makefile 1.19%
swift json-files json-generator swift5 codeable marshalling json hacktoberfest

swiftyjsonaccelerator's Introduction

Logo

SwiftyJSONAccelerator - MacOS app Codeable Model file Generator For Swift 5

Build Status codecov

Installing & Building

  • Building:

    pod install
    

    You will also need to install SwiftFormat with brew install swiftformat and SwiftLint with brew install swiftlint.

  • Download dmg: Download the .app (v2.2.0)

Common Issues

  • SwiftyJSONAccelerator can't be opened because Apple cannot check it for malicious software.: Run the following command xattr -d com.apple.quarantine <app-path>.

Features

Logo

A Swift model generator like the Objective-C JSONAccelerator. Formats and generates models for the given JSON and also breaks them into files making it easy to manage and share between several models.

  • The models that are generated depend Swift's inbuilt Codeable feature making encoding and decoding objects a thing of the past.
  • Allows to opt for either optional or non-optional variables.
  • Allows an array of a certain object type with different properties to be merged into a single model with all properties.
  • Click Load folder with JSON files + Config to generate all possible models for given folder with JSON files, note this needs a .config.json as this uses the CLI logic internally.

Contributions and Requests

Any suggestions regarding code quality of the app, generated code's quality, Swift related improvements and pull requests are all very welcome. Please make sure you submit the pull request to the next release branch and not the master branch.

swiftyjsonaccelerator's People

Contributors

amyleecodes avatar cntrump avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar donlinglok avatar insanoid avatar kchatzigeorgiou avatar romanpodymov avatar sabinahuseinova avatar yonihemi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftyjsonaccelerator's Issues

Build a CLI interface

The project is modular now, a CLI interface can be built to generate model on the fly without the UI, will help in integration with API mocks etc.

Merge Generated classes

I want to know is there any solution i want to merge classes.
Like currently it create 2 3 classes but i want to merge them and use only one.
I can do in jsonaccelerator for objective C but i cant do it in swifty json

Can't install the app

I downloaded the app only, but I can't install it.
When I try to install it, there is a message that says "[...] you should move it to the trash".
I also allowed on my Mac the installation of the apps from anywhere.

In addition, I run the following command line on terminal:

spctl -a <my_path>/SwiftyJSONAccelerator.app

but the return message is the following:

CSSMERR_TP_CERT_REVOKED

Please, help!

Support the ability to modify templates at runtime.

I think it would be interesting and useful to support the ability to edit templates at runtime.
I think by taking the already in place parameters and creating a simple click and insert interface, you can easily allow the end user to modify the template without having the source.

Further thought:
Maybe include a feature to export custom templates for sharing, based on new paradigms, etc.

Parse date strings to Date() objects

Is it possible for the soft to detect dates using, for example, regex? If yes, it may be possible to perform the feature that would parse the date in strings into Date() objects.

Failing build

My build is failing with the following error:

▸ Copying SwiftyJSONAccelerator/Templates/BaseTemplate.txt
▸ Copying SwiftyJSONAccelerator/Templates/Library-Extension-Templates/MarshalTemplate.txt
▸ Generating 'SwiftyJSONAccelerator.app.dSYM'
▸ Running script 'SwiftLint'
** BUILD FAILED **


The following build commands failed:
	PhaseScriptExecution SwiftLint /Users/jonah.neugass/Library/Developer/Xcode/DerivedData/SwiftyJSONAccelerator-bcwgjtlsrftxmvdldjpdtlzwhrfb/Build/Intermediates/SwiftyJSONAccelerator.build/Release/SwiftyJSONAccelerator.build/Script-930462B91D311F9100FE61A6.sh
(1 failure)
 ✓ SwiftyJSONAccelerator app and CLI successfully installed!! 🍻
 ✓ Use the app from Applications or ./swiftyjsonaccelerator

Platform: Sierra 10.12.4
Xcode: 8.3.2

Error with Array JSON

Hello, I try to do this example

{
  "pagination": {
    "total_pages": 1,
    "total_items": 1
  },
  "items": [
    {
      "id": "1",
      "name": "Area1"
    }
  ]
}

And in this line i have a problem

public required init(json: JSON) {
    if let items = json[SerializationKeys.items].array { items = items.map { Items(json: $0) } } //-------Cannot assign to value. 'items' is a 'let' constant
    pagination = Pagination(json: json[SerializationKeys.pagination])
  }

How can realize this struct?

Thanks!

Add tests

  • Add tests for the file generation.
  • Add tests for JSON parser.
  • Integrate with CI.
  • Add badges to the README file.

Methods an error

public required init(json: JSON) {
if let items = json[SerializationKeys.items].array { items = items.map { HomeItemsItems(json: $0) } }
}

Generics - Is possible to do this?

Now i have an object "ListOfItems" for all list of my project, but I would like ListOfItems or ListOfItems with only one class. Could be do it with generics in SwiftyJSONAccelerator?

{ "pagination": { "total_pages": 1, "total_items": 2 }, "items": [ { "id": "1", "name": "Section 1" }, { "id": "2", "name": "Section 2" } ] }

Other:

{ "pagination": { "total_pages": 1, "total_items": 1 }, "items": [ { "id": "1", "title": "Car 1" "price": 30000 } ] }

Thanks, your work is awesome ;)

Methods an erro

public required init(json: JSON) {
if let items = json[SerializationKeys.items].array { items = items.map { HomeItemsItems(json: $0) } }
}

Suggestion: Adding Entities Names?

Is there any way we can add the name of generated entities ? like having a preview of names of files appear and then we can change name regarding our requirement.

1.4.0 crashed with macOS 10.1

Here is the detail crash info:

Exception Name: NSInvalidArgumentException
Description: Could not find a storyboard named 'Main' in bundle NSBundle </private/var/folders/p2/k10207q550b481p6jvwh9lpr0000gn/T/AppTranslocation/261BEBED-43F7-4CDC-8F1D-D458C283BD28/d/SwiftyJSONAccelerator.app> (loaded)
User Info: (null)
0 CoreFoundation 0x00007fffa4ff252b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffb96cacad objc_exception_throw + 48
2 AppKit 0x00007fffa3385485 -[NSStoryboard storyboardFileName] + 0
3 AppKit 0x00007fffa2bbf744 NSApplicationMain + 399
4 SwiftyJSONAccelerator 0x0000000100c2fc39 main + 73
5 libdyld.dylib 0x00007fffb9fa8255 start + 1

Will there be any updates in the future?

Swift 4.2 is coming, or rather it already came. And there must be a further support or bug fixing.

For instance, I sometimes need the generated model class by SwiftJSONAccelerator to subclass the NSObject to support some stuff. And currently, I am experiencing crashes in decodeBool.

Crash:

self.first = aDecoder.decodeBool(forKey: SerializationKeys.first)
self.last = aDecoder.decodeBool(forKey: SerializationKeys.last)

Fix:

self.first = aDecoder.decodeObject(forKey: SerializationKeys.first) as? Bool
self.last = aDecoder.decodeObject(forKey: SerializationKeys.last) as? Bool

Thank you!

1.4.0 crashed with macOS 10.12

Here is the detail crash info:

Exception Name: NSInvalidArgumentException
Description: Could not find a storyboard named 'Main' in bundle NSBundle </private/var/folders/p2/k10207q550b481p6jvwh9lpr0000gn/T/AppTranslocation/261BEBED-43F7-4CDC-8F1D-D458C283BD28/d/SwiftyJSONAccelerator.app> (loaded)
User Info: (null)
0 CoreFoundation 0x00007fffa4ff252b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffb96cacad objc_exception_throw + 48
2 AppKit 0x00007fffa3385485 -[NSStoryboard storyboardFileName] + 0
3 AppKit 0x00007fffa2bbf744 NSApplicationMain + 399
4 SwiftyJSONAccelerator 0x0000000100c2fc39 main + 73
5 libdyld.dylib 0x00007fffb9fa8255 start + 1

Swift 3 compatibility

Hey, I'd love to see this lib available in Swift 3 so I can implement it in my project.

Thanks 😄

Memory Leak - App Crash Randomly

Hello I am using SwiftyJSONAccelerator Tool for crating model but its create memory leak.

Please review below code.

let json = JSON(response.result.value!)
let objInternationalPackageModel = InternationalPackage(json:json)

If I will comment above two lines than Memory leak is remove.

Below is my model class object -

public final class InternationalPackage: NSCoding {

  // MARK: Declaration for string constants to be used to decode and also serialize.
  private struct SerializationKeys {
    static let status        = "status"
    static let data          = "data"
    static let message       = "message"
    static let currencyImage = "CurrencyImage"
    static let isUser        = "IsUser"
  }

  // MARK: Properties
  public var status       : Int?
  public var data         : [InternationalpackageData]?
  public var message      : String?
  public var currencyImage: [CurrencyImage]?
  public var isUser       : Int?

  // MARK: SwiftyJSON Initializers
  /// Initiates the instance based on the object.
  ///
  /// - parameter object: The object of either Dictionary or Array kind that was passed.
  /// - returns: An initialized instance of the class.
  public convenience init(object: Any) {
    self.init(json: JSON(object))
  }
    
  /// Initiates the instance based on the JSON that was passed.
  ///
  /// - parameter json: JSON object from SwiftyJSON.
  public required init(json: JSON) {
    status       = json[SerializationKeys.status].int
    if let items = json[SerializationKeys.data].array { data = items.map { InternationalpackageData(json: $0) } }
    message      = json[SerializationKeys.message].string
    if let items = json[SerializationKeys.currencyImage].array { currencyImage = items.map { CurrencyImage(json: $0) } }
    isUser       = json[SerializationKeys.isUser].int
  }

  /// Generates description of the object in the form of a NSDictionary.
  ///
  /// - returns: A Key value pair containing all valid values in the object.
  public func dictionaryRepresentation() -> [String: Any] {
    var dictionary: [String: Any] = [:]
    if let value = status { dictionary[SerializationKeys.status] = value }
    if let value = data { dictionary[SerializationKeys.data] = value.map { $0.dictionaryRepresentation() } }
    if let value = message { dictionary[SerializationKeys.message] = value }
    if let value = currencyImage { dictionary[SerializationKeys.currencyImage] = value.map { $0.dictionaryRepresentation() } }
    if let value = isUser { dictionary[SerializationKeys.isUser] = value }
    return dictionary
  }

  // MARK: NSCoding Protocol
  required public init(coder aDecoder: NSCoder) {
    self.status        = aDecoder.decodeObject(forKey: SerializationKeys.status) as? Int
    self.data          = aDecoder.decodeObject(forKey: SerializationKeys.data) as? [InternationalpackageData]
    self.message       = aDecoder.decodeObject(forKey: SerializationKeys.message) as? String
    self.currencyImage = aDecoder.decodeObject(forKey: SerializationKeys.currencyImage) as? [CurrencyImage]
    self.isUser        = aDecoder.decodeObject(forKey: SerializationKeys.isUser) as? Int
  }

  public func encode(with aCoder: NSCoder) {
    aCoder.encode(status, forKey: SerializationKeys.status)
    aCoder.encode(data, forKey: SerializationKeys.data)
    aCoder.encode(message, forKey: SerializationKeys.message)
    aCoder.encode(currencyImage, forKey: SerializationKeys.currencyImage)
    aCoder.encode(isUser, forKey: SerializationKeys.isUser)
  }

}

can we have a chance to set the name of a sub class?

when json file is big,we get a lot of files with a default name, these names will not always match, it will be better to have a chance to set the name of every sub class before we export it. that will be awesome.

App Installation with CLI Failed

Hi,

I think this library was so great that helps developers to create their models in an instant, that is why I want to try this but unfortunately I am stuck in the installation with CLI. Please see the image below.

I am just following the steps, and even I add sudo in the make install same error occurs. I am also newbie in linux.

Hope anyone can help me.

Thank you.

screen shot 2017-06-09 at 8 37 33 am

Crash after generating class files

Thanks for the great app!

Unfortunately I loaded it up today and it was consistently crashing after the model generation. It doesn't seem like a huge functionality issue since the class files are generated successfully, but it just crashes after that.

Here's a crash report. This is reproducible every time.

Steps to reproduce:

  1. Load input area with valid JSON
  2. Click 'generate' and select the directory.
  3. Observe the crash. Class files will be in the directory though.

Struct support

Generated files should provide an option to choose between struct and class.

Add Realm RLMObject support?

We're using Realm in a lot of our projects, RLMObject subclasses (in addition to Mappable, which we're using too) would be sweet! This is an example of what our classes look like:

class Employee: RLMObject, Mappable{
    
    dynamic var id: Int = 0;
    dynamic var locationId: Int = 0;
    dynamic var firstName: String = "";
    dynamic var lastName: String = "";
    dynamic var phone: String = "";
    dynamic var email: String = "";
    
    override static func primaryKey() -> String? {
        return "id"
    }
    
    //Impl. of Mappable protocol
    required convenience init?(map: Map) {
        self.init()
    }
    
    required public override init() {
        super.init()
    }
    
    func mapping(map: Map) {
        id    <- map["ID"]
        locationId <- map["LocationID"]
        firstName <- map["FirstName"]
        lastName <- map["LastName"]
        phone <- map["Phone"]
        email <- map["Email"]
    }

Can not generate class ESRI JSON route service

I am using ESRI route service I want to convert object from this (JSON Link) with SwiftyJSONAccelerator. But I have a problem one class. This class name "paths" (route array). I think this problem usage array in array. I tried to fix it, but it did not.

How can I fix. I'm glad you helped me.

RouteResult.zip

NSCoding issue

In V->1.0.0 NSCoding code is not coming even NSCoding Check is enabled.
also class is not creating.

please look into this issue, ASAP. thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.