Skip to content

Commit

Permalink
-fix for full support for swift 2.0 , Xcode 7.0
Browse files Browse the repository at this point in the history
-fix issue lazy sequence for array ,to support 2.0 swift
-fix optionals for NSURL
  • Loading branch information
tufnica authored and Branko Grbic committed Sep 26, 2015
1 parent f8eec63 commit a7698e8
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 98 deletions.
2 changes: 2 additions & 0 deletions JSONExport.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@
E2FA87AD1A059AC100648EB6 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = "Ahmed Ali";
TargetAttributes = {
Expand Down
2 changes: 1 addition & 1 deletion JSONExport/DataType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DataType{
*/
func toDictionary() -> NSDictionary
{
var dictionary = NSMutableDictionary()
let dictionary = NSMutableDictionary()
if boolType != nil{
dictionary["boolType"] = boolType
}
Expand Down
70 changes: 35 additions & 35 deletions JSONExport/FileContentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class FilesContentBuilder{
/**
Generates a file using the passed className and jsonObject example and appends it in the passed files array

:param: className for the file to be generated, if the file already exist with different name, this className will be changed
:param: jsonObject acts as an example of the json object, which the generated fill be able to handle
:param: files the generated file will be appended to this array
- parameter className: for the file to be generated, if the file already exist with different name, this className will be changed
- parameter jsonObject: acts as an example of the json object, which the generated fill be able to handle
- parameter files: the generated file will be appended to this array
*/
func addFileWithName(inout className: String, jsonObject: NSDictionary, inout files : [FileRepresenter], toOneRelationWithProperty: Property! = nil)
{
Expand All @@ -77,14 +77,14 @@ class FilesContentBuilder{

}
//sort all the keys in the passed json dictionary
var jsonProperties = sorted(jsonObject.allKeys as! [String])
let jsonProperties = (jsonObject.allKeys as! [String]).sort()

//loop all the json properties and handle each one individually
for jsonPropertyName in jsonProperties{
let value : AnyObject = jsonObject[jsonPropertyName]!
let property = propertyForValue(value, jsonKeyName: jsonPropertyName)
//Avoid duplicated property names
if let index = find(properties.map({$0.nativeName}), property.nativeName){
if let index = properties.map({$0.nativeName}).indexOf(property.nativeName){
continue
}
//recursively handle custom types
Expand Down Expand Up @@ -146,13 +146,13 @@ class FilesContentBuilder{

/**
Merges the properties from the passed fromFile to the pass toFile
:param: fromFile in which to find any new properties
:param: toFile to which to add any found new properties
- parameter fromFile: in which to find any new properties
- parameter toFile: to which to add any found new properties
*/
func mergeProperties(#fromFile: FileRepresenter, toFile: FileRepresenter)
func mergeProperties(fromFile fromFile: FileRepresenter, toFile: FileRepresenter)
{
for property in fromFile.properties{
if find(toFile.properties, property) == nil{
if toFile.properties.indexOf(property) == nil{
toFile.properties.append(property)
}
}
Expand All @@ -161,10 +161,10 @@ class FilesContentBuilder{
/**
Finds the first file in the passed files which has the same class name as the passed file

:param: file the file to compare against
:param: inFiles the files array to search in
:param: exactMathFound inout param, will have the value of 'true' if any file is found that has exactly the same properties as the passed file
:returns: similar file if any
- parameter file: the file to compare against
- parameter inFiles: the files array to search in
- parameter exactMathFound: inout param, will have the value of 'true' if any file is found that has exactly the same properties as the passed file
- returns: similar file if any
*/
func findSimilarFile(file: FileRepresenter, inFiles files: [FileRepresenter], inout exactMatchFound: Bool) -> FileRepresenter?{
var similarFile : FileRepresenter?
Expand All @@ -185,17 +185,17 @@ class FilesContentBuilder{
/**
Compares the properties of both files to determine if they exactly similar or no.

:param: file1 first file to compare against the second file
:param: file2 the second file to compare against the first file
:returns: whether both files has exactly the same properties
- parameter file1: first file to compare against the second file
- parameter file2: the second file to compare against the first file
- returns: whether both files has exactly the same properties
*/
func bothFilesHasSamePropreties(#file1: FileRepresenter, file2: FileRepresenter) -> Bool
func bothFilesHasSamePropreties(file1 file1: FileRepresenter, file2: FileRepresenter) -> Bool
{
var bothHasSameProperties = true
if file1.properties.count == file2.properties.count{
//there is a propability they both has the same properties
for property in file1.properties{
if find(file2.properties, property) == nil{
if file2.properties.indexOf(property) == nil{
//property not found, no need to keep looking
bothHasSameProperties = false
break
Expand Down Expand Up @@ -226,10 +226,10 @@ class FilesContentBuilder{
/**
Creates and returns a Property object whiche represents a to-one relation property

:param: relationClassName to which the relation relates
:param: headerProperty optional whether this property is for header file
- parameter relationClassName: to which the relation relates
- parameter headerProperty: optional whether this property is for header file

:returns: the relation property
- returns: the relation property
*/
func relationProperty(relationClassName : String) -> Property
{
Expand All @@ -244,9 +244,9 @@ class FilesContentBuilder{
/**
Creates and returns a Property object passed on the passed value and json key name

:param: value example value for the property
:param: jsonKeyName for the property
:returns: a Property instance
- parameter value: example value for the property
- parameter jsonKeyName: for the property
- returns: a Property instance
*/
func propertyForValue(value: AnyObject, jsonKeyName: String) -> Property
{
Expand Down Expand Up @@ -291,16 +291,16 @@ class FilesContentBuilder{
/**
Returns a camel case presentation from the passed json key

:param: jsonKeyName the name of the json key to convert to suitable native property name
- parameter jsonKeyName: the name of the json key to convert to suitable native property name

:returns: property name
- returns: property name
*/
func propertyNativeName(jsonKeyName : String) -> String
{
var propertyName = cleanUpVersionOfPropertyNamed(jsonKeyName)
propertyName = underscoresToCamelCaseForString(propertyName, startFromFirstChar: false).lowercaseFirstChar()
//Fix property name that could be a reserved keyword
if lang.reservedKeywords != nil && contains(lang.reservedKeywords, propertyName.lowercaseString){
if lang.reservedKeywords != nil && lang.reservedKeywords.contains(propertyName.lowercaseString){
//Property name need to be suffixed by proper suffix, any ideas of better generlized prefix/suffix?
propertyName += "Field"
}
Expand All @@ -310,19 +310,19 @@ class FilesContentBuilder{

func cleanUpVersionOfPropertyNamed(propertyName: String) -> String
{
var allowedCharacters = NSMutableCharacterSet.alphanumericCharacterSet()
let allowedCharacters = NSMutableCharacterSet.alphanumericCharacterSet()
allowedCharacters.addCharactersInString("_1234567890")
var notAllowedCharacters = allowedCharacters.invertedSet
let cleanVersion = join("", propertyName.componentsSeparatedByCharactersInSet(allowedCharacters.invertedSet))
let cleanVersion = propertyName.componentsSeparatedByCharactersInSet(allowedCharacters.invertedSet).joinWithSeparator("")
return cleanVersion
}

/**
Returns the input string with white spaces removed, and underscors converted to camel case

:param: inputString to convert
:param: startFromFirstChar whether to start with upper case letter
:returns: the camel case version of the input
- parameter inputString: to convert
- parameter startFromFirstChar: whether to start with upper case letter
- returns: the camel case version of the input
*/
func underscoresToCamelCaseForString(input: String, startFromFirstChar: Bool) -> String
{
Expand All @@ -331,7 +331,7 @@ class FilesContentBuilder{
str = str.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
var output = ""
var makeNextCharUpperCase = startFromFirstChar
for char in input{
for char in input.characters{
if char == "_" {
makeNextCharUpperCase = true
}else if makeNextCharUpperCase{
Expand All @@ -350,8 +350,8 @@ class FilesContentBuilder{
/**
Creats and returns the class name for the passed proeprty name

:param: propertyName to be converted to a type name
:returns: the type name
- parameter propertyName: to be converted to a type name
- returns: the type name
*/
func typeNameForPropertyName(propertyName : String) -> String{
var swiftClassName = underscoresToCamelCaseForString(propertyName, startFromFirstChar: true).toSingular()
Expand Down
24 changes: 12 additions & 12 deletions JSONExport/FileRepresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class FileRepresenter{
appendCustomImports()
//start the model defination
var definition = ""
if lang.modelDefinitionWithParent != nil && count(parentClassName) > 0{
if lang.modelDefinitionWithParent != nil && parentClassName.characters.count > 0{
definition = lang.modelDefinitionWithParent.stringByReplacingOccurrencesOfString(modelName, withString: className)
definition = definition.stringByReplacingOccurrencesOfString(modelWithParentClassName, withString: parentClassName)
}else if includeUtilities && lang.defaultParentWithUtilityMethods != nil{
Expand Down Expand Up @@ -128,7 +128,7 @@ class FileRepresenter{
*/
func appendFirstLineStatement()
{
if lang.supportsFirstLineStatement != nil && lang.supportsFirstLineStatement! && count(firstLine) > 0{
if lang.supportsFirstLineStatement != nil && lang.supportsFirstLineStatement! && firstLine.characters.count > 0{
fileContent += "\(firstLine)\n\n"
}
}
Expand Down Expand Up @@ -187,15 +187,15 @@ class FileRepresenter{
*/
func getYear() -> String
{
return "\(NSCalendar.currentCalendar().component(.CalendarUnitYear, fromDate: NSDate()))"
return "\(NSCalendar.currentCalendar().component(.Year, fromDate: NSDate()))"
}

/**
Returns today date in the format dd/mm/yyyy
*/
func getTodayFormattedDay() -> String
{
let components = NSCalendar.currentCalendar().components(.CalendarUnitDay | .CalendarUnitMonth | .CalendarUnitYear, fromDate: NSDate())
let components = NSCalendar.currentCalendar().components([.Day, .Month, .Year], fromDate: NSDate())
return "\(components.day)/\(components.month)/\(components.year)"
}

Expand Down Expand Up @@ -224,7 +224,7 @@ class FileRepresenter{
fileContent += "\n"
for property in properties{

fileContent += property.toString(forHeaderFile: false)
fileContent += property.toString(false)
}
}

Expand Down Expand Up @@ -326,7 +326,7 @@ class FileRepresenter{
}
propertyHandlingStr = propertyHandlingStr.stringByReplacingOccurrencesOfString(elementType, withString: property.elementsType)
}else{
if lang.basicTypesWithSpecialStoringNeeds != nil && method.forEachPropertyWithSpecialStoringNeeds != nil && find(lang.basicTypesWithSpecialStoringNeeds, property.type) != nil{
if lang.basicTypesWithSpecialStoringNeeds != nil && method.forEachPropertyWithSpecialStoringNeeds != nil && lang.basicTypesWithSpecialStoringNeeds.indexOf(property.type) != nil{
propertyHandlingStr = method.forEachPropertyWithSpecialStoringNeeds
}else{
propertyHandlingStr = method.forEachProperty
Expand All @@ -344,7 +344,7 @@ class FileRepresenter{

propertyHandlingStr = propertyHandlingStr.stringByReplacingOccurrencesOfString(additionalCustomTypeProperty, withString:"")
if lang.basicTypesWithSpecialFetchingNeeds != nil{
if let index = find(lang.basicTypesWithSpecialFetchingNeeds, property.type), let replacement = lang.basicTypesWithSpecialFetchingNeedsReplacements?[index]{
if let index = lang.basicTypesWithSpecialFetchingNeeds.indexOf(property.type), let replacement = lang.basicTypesWithSpecialFetchingNeedsReplacements?[index]{
propertyHandlingStr = propertyHandlingStr.stringByReplacingOccurrencesOfString(varTypeReplacement, withString: replacement)


Expand All @@ -367,13 +367,13 @@ class FileRepresenter{
*/
func propertyTypeIsBasicType(property: Property) -> Bool{
var isBasicType = false
var type = propertyTypeWithoutArrayWords(property)
let type = propertyTypeWithoutArrayWords(property)
if lang.genericType == type{
isBasicType = true
}else{
let basicTypes = lang.dataTypes.toDictionary().allValues as! [String]

if find(basicTypes, type) != nil{
if basicTypes.indexOf(type) != nil{
isBasicType = true
}
}
Expand All @@ -394,7 +394,7 @@ class FileRepresenter{
type = type.stringByReplacingOccurrencesOfString(arrayWord, withString: "")
}

if count(type) == 0{
if type.characters.count == 0{
type = typeNameForArrayElements(property.sampleValue as! NSArray, lang: lang)
}
return type
Expand Down Expand Up @@ -438,7 +438,7 @@ class FileRepresenter{
if(propertyTypeIsBasicType(property)){

if constructor.fetchArrayOfBasicTypePropertyFromMap != nil{
if let index = find(lang.basicTypesWithSpecialFetchingNeeds, property.elementsType){
if let index = lang.basicTypesWithSpecialFetchingNeeds.indexOf(property.elementsType){
propertyStr = constructor.fetchArrayOfBasicTypePropertyFromMap
let replacement = lang.basicTypesWithSpecialFetchingNeedsReplacements[index]
propertyStr = propertyStr.stringByReplacingOccurrencesOfString(varTypeReplacement, withString: replacement)
Expand Down Expand Up @@ -467,7 +467,7 @@ class FileRepresenter{
{
var propertyStr = ""
if lang.basicTypesWithSpecialFetchingNeeds != nil{
let index = find(lang.basicTypesWithSpecialFetchingNeeds, property.type)
let index = lang.basicTypesWithSpecialFetchingNeeds.indexOf(property.type)
if index != nil{
propertyStr = constructor.fetchBasicTypeWithSpecialNeedsPropertyFromMap
if let replacement = lang.basicTypesWithSpecialFetchingNeedsReplacements?[index!]{
Expand Down
8 changes: 4 additions & 4 deletions JSONExport/HeaderFileRepresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class HeaderFileRepresenter : FileRepresenter{

//start the model defination
var definition = ""
if lang.headerFileData.modelDefinitionWithParent != nil && count(parentClassName) > 0{
if lang.headerFileData.modelDefinitionWithParent != nil && parentClassName.characters.count > 0{
definition = lang.headerFileData.modelDefinitionWithParent.stringByReplacingOccurrencesOfString(modelName, withString: className)
definition = definition.stringByReplacingOccurrencesOfString(modelWithParentClassName, withString: parentClassName)
}else if includeUtilities && lang.defaultParentWithUtilityMethods != nil{
Expand Down Expand Up @@ -82,7 +82,7 @@ class HeaderFileRepresenter : FileRepresenter{

func appendImportParentHeader()
{
if lang.headerFileData.importParentHeaderFile != nil && count(parentClassName) > 0{
if lang.headerFileData.importParentHeaderFile != nil && parentClassName.characters.count > 0{
fileContent += lang.headerFileData.importParentHeaderFile.stringByReplacingOccurrencesOfString(modelWithParentClassName, withString: parentClassName)
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@ class HeaderFileRepresenter : FileRepresenter{
//if it is an array of custom types
if(property.elementsType != lang.genericType){
let basicTypes = lang.dataTypes.toDictionary().allValues as! [String]
if find(basicTypes, property.elementsType) == nil{
if basicTypes.indexOf(property.elementsType) == nil{
fileContent += lang.headerFileData.importForEachCustomType.stringByReplacingOccurrencesOfString(modelName, withString: property.elementsType)
}
}
Expand All @@ -146,7 +146,7 @@ class HeaderFileRepresenter : FileRepresenter{
{
fileContent += "\n"
for property in properties{
fileContent += property.toString(forHeaderFile: true)
fileContent += property.toString(true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion JSONExport/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.8</string>
<string>0.0.9</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
4 changes: 2 additions & 2 deletions JSONExport/Property.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ class Property : Equatable{
{
var string : String!
if forHeaderFile{
if lang.headerFileData.instanceVarWithSpeicalDefinition != nil && find(lang.headerFileData.typesNeedSpecialDefinition, type) != nil{
if lang.headerFileData.instanceVarWithSpeicalDefinition != nil && lang.headerFileData.typesNeedSpecialDefinition.indexOf(type) != nil{
string = lang.headerFileData.instanceVarWithSpeicalDefinition
}else{
string = lang.headerFileData.instanceVarDefinition
}


}else{
if lang.instanceVarWithSpeicalDefinition != nil && find(lang.typesNeedSpecialDefinition, type) != nil{
if lang.instanceVarWithSpeicalDefinition != nil && lang.typesNeedSpecialDefinition.indexOf(type) != nil{
string = lang.instanceVarWithSpeicalDefinition
}else{
string = lang.instanceVarDefinition
Expand Down
Loading

0 comments on commit a7698e8

Please sign in to comment.