Skip to content

Repository files navigation

Installation

  1. Clone or download the repo
  2. Open CodeGenerator.xcodeproj
  3. Enable target signing for both the Application and the Source Code Extension using your own developer ID
  4. Select the application target and then Product > Archive
  5. Export the archive as a macOS App
  6. Run the app, then quit (Don't delete the app, put it in a convenient folder)
  7. Go to System Preferences -> Extensions -> Xcode Source Editor and enable the CodeGenerator extension
  8. The menu-item should now be available from Xcode's Editor menu

Uninstallation

  1. Remove the App, restart Xcode.

CodeGenerator

CodeGenerator is a Xcode extension for swift code generation.

alt tag

Generating mock

Example:

protocolPokemon{varheight:Double!{getset}varcanEvolve:Bool!{get}func eat(food:String)func drink(_ water:String)func isFlying()->Boolfunc evolve(successHandler:@escaping(String)->Void, failureHandler:(String?)->String?)}
classPokemonMock:Pokemon{varheight:Double!varcanEvolve:Bool!vareatFood:String?vardrinkWater:String?varevolveShouldCallSuccessHandler=truevarevolveSuccessHandlerParam0:String!varevolveShouldCallFailureHandler=truevarevolveFailureHandlerParam0:String!varevolveFailureHandlerDidReturn:String?vareatFoodWasCalled:Bool?vardrinkWasCalled:Bool?varisFlyingWasCalled:Bool?varevolveSuccessHandlerWasCalled:Bool?varisFlyingShouldReturn:Bool!func eat(food:String){
eatFood = food
eatFoodWasCalled =true}func drink(_ water:String){
drinkWater = water
drinkWasCalled =true}func isFlying()->Bool{
isFlyingWasCalled =truereturn isFlyingShouldReturn
}func evolve(successHandler:@escaping(String)->Void, failureHandler:(String?)->String?){if evolveShouldCallSuccessHandler {successHandler(evolveSuccessHandlerParam0)}if evolveShouldCallFailureHandler {
evolveFailureHandlerDidReturn =failureHandler(evolveFailureHandlerParam0)}
evolveSuccessHandlerWasCalled =true}}

Generating Equatable

Example:

classEquatableClazz{varvar0:Int!letvar1:Stringvarvar2:Bool?}
extensionEquatableClazz:Equatable{staticfunc==(lhs:EquatableClazz, rhs:EquatableClazz)->Bool{return lhs.var0 == rhs.var0 && lhs.var1 == rhs.var1 && lhs.var2 == rhs.var2
}}

if you don't want to use all the vars for the Equatable, just select the vars you want and click Generate... -> Equatable

Generating Hashable

Example:

classEquatableClazz{varvar0:Int!letvar1:Stringvarvar2:Bool?}
extensionEquatableClazz:Hashable{staticfunc==(lhs:EquatableClazz, rhs:EquatableClazz)->Bool{return lhs.var0 == rhs.var0 && lhs.var1 == rhs.var1 && lhs.var2 == rhs.var2
}varhashValue:Int{varhashValue=1lethashableVars:[AnyHashable?]=[var0, var1, var2]
hashableVars.forEach{
hashValue =31* hashValue +($0?.hashValue ??0)}return hashValue
}}

Generating Init

Example:

classEquatableClazz{varvar0:Int!letvar1:Stringvarvar2:Bool?init(var0:Int?, var1:String, var2:Bool?){self.var0 = var0
self.var1 = var1
self.var2 = var2
}}

Generating NSCoding

Example:

classEquatableClazz{varvar0:Intletvar1:Stringvarvar2:Bool?requiredinit?(coder aDecoder:NSCoder){guardlet var1 = aDecoder.decodeObject(forKey:"var1")as?Stringelse{returnnil}
var0 = aDecoder.decodeInteger(forKey:"var0")self.var1 = var1
if aDecoder.containsValue(forKey:"var2"){
var2 = aDecoder.decodeBool(forKey:"var2")}}func encode(with aCoder:NSCoder){
aCoder.encode(var0, forKey:"var0")
aCoder.encode(var1, forKey:"var1")
aCoder.encode(var2, forKey:"var2")}}

About

No description or website provided.

Topics

Resources

Stars

74 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages