Majority of the mobile apps communicates with api. We are always writing get and post request for every app and for every api. It is a redundant job That cannot be skipped.
But we can sure automate it.
Introducing veda-apps . It is a collection of tools used frequently in ios. There are many features yet to come. But for now lets us generate our files from url.
Open terminal: Enter
gem install veda-apps , or sometimes, sudo gem install veda-apps
now enter: veda
you should see something like this
We can generate model with url, but some url needs headers like authorization, api-keys so in order to manage all of it. first we create a config file. which will contain all the credential.
veda generate model config
This will create a config.json file in the current directory. config file contains placeholders elements that need to be updated by you.
"OtherHeaders": "add as your need"
replace “url” with your url and headers according to your need.
veda generate model
=> This will load your config file, fetch the json from url and parse it. It will generate all the class in different files in current directory.
=> You can create model from json file as well. suppose you have input.json file that contains the json response.
veda generate model -f input.json
This will read json from input.json and parse it.
But it does not end here. It supports the realm as well.
veda generate model –realm
veda generate model -f input.json –realm
it generates all ready made class files that have the default values. And is ready to be saved in the realm.
since in swift we write camelCased. But data from ruby or php like servers give us in snake_case format. All variable names are automatically changed to camelCased.
make sure your podfile have this.
import ObjectMapper import RealmSwift
in your pod file. and
pod install is success
you can change the default values according to your needs.