From dba54c4dfca31fa5f8807a89fdfd68781f541652 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa KM Date: Sat, 10 Jun 2017 13:47:26 +0200 Subject: [PATCH 1/2] Updated UI (#71) * Update UI Elements * Fixed issues raised in CR I have kept your layout, just cleaned up some UX flaws. Also, fixed some swxftlint issues. * fixed issue with enum case names --- .swiftlint.yml | 1 + Core/Constants.swift | 44 +-- Core/Generators/ModelGenerator.swift | 32 +- Core/Generators/MultipleModelGenerator.swift | 27 +- Core/Helpers/JSON+Helpers.swift | 14 +- .../FileGeneratorExtension.swift | 12 +- .../Library-Extensions/MarshalModelFile.swift | 14 +- .../ObjectMapperModelFile.swift | 14 +- .../SwiftyJSONModelFile.swift | 16 +- .../DefaultModelFileComponent.swift | 8 +- .../ModelGenerationConfiguration.swift | 6 +- .../Storyboard/Main.storyboard | 274 ++++++++++-------- SwiftyJSONAccelerator/Support/Info.plist | 4 +- .../UI/SJEditorViewController.swift | 12 +- .../ModelGeneratorTests.swift | 28 +- 15 files changed, 273 insertions(+), 233 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 439e9a3..bd8eaab 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -3,6 +3,7 @@ disabled_rules: # rule identifiers to exclude from running - function_body_length - unused_closure_parameter - valid_docs + - large_tuple excluded: # paths to ignore during linting. Takes precedence over `included`. - SwiftyJSONAcceleratorTests - Pods diff --git a/Core/Constants.swift b/Core/Constants.swift index 7960f6d..db67151 100644 --- a/Core/Constants.swift +++ b/Core/Constants.swift @@ -20,25 +20,25 @@ import Foundation - Object: Object. */ enum VariableType: String { - case String = "String" - case Int = "Int" - case Float = "Float" - case Double = "Double" - case Bool = "Bool" - case Array = "[]" - case Object = "{OBJ}" - case Null = "Any" + case string = "String" + case int = "Int" + case float = "Float" + case double = "Double" + case bool = "Bool" + case array = "[]" + case object = "{OBJ}" + case null = "Any" } /** Various types of construct that can be generated. - - ClassType: Model with construct type class. - - StructType: Model with construct type struct. + - classType: Model with construct type class. + - structType: Model with construct type struct. */ enum ConstructType: String { - case ClassType = "class" - case StructType = "struct" + case classType = "class" + case structType = "struct" } /** @@ -49,9 +49,9 @@ enum ConstructType: String { - Marshal: Marshal - https://github.com/utahiosmac/Marshal */ enum JSONMappingLibrary: String { - case SwiftyJSON - case ObjectMapper - case Marshal + case libSwiftyJSON = "SwiftyJSON" + case libObjectMapper = "ObjectMapper" + case libMarshal = "Marshal" } /** @@ -61,14 +61,14 @@ enum JSONMappingLibrary: String { - ValueArray: Array of Value - Object: Object type - ObjectArray: Array of object - - EmptyArray: An empty array + - emptyArray: An empty array - Null: Null value */ enum PropertyType: String { - case ValueType - case ValueTypeArray - case ObjectType - case ObjectTypeArray - case EmptyArray - case NullType + case valueType + case valueTypeArray + case objectType + case objectTypeArray + case emptyArray + case nullType } diff --git a/Core/Generators/ModelGenerator.swift b/Core/Generators/ModelGenerator.swift index 876659f..f3f7634 100644 --- a/Core/Generators/ModelGenerator.swift +++ b/Core/Generators/ModelGenerator.swift @@ -56,7 +56,7 @@ public struct ModelGenerator { let subClassType = firstObject.detailedValueType() // If the type of the first item is an object then make it the base class and generate // stuff. However, currently it does not make a base file to handle the array. - if subClassType == .Object { + if subClassType == .object { return self.generateModelForJSON(JSONHelper.reduce(rootObject), defaultClassName, isTopLevelObject) } return [] @@ -76,32 +76,32 @@ public struct ModelGenerator { let stringConstantName = NameGenerator.variableKey(className, variableName) switch variableType { - case .Array: + case .array: if value.arrayValue.count <= 0 { - currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, VariableType.Array.rawValue, stringConstantName, key, .EmptyArray)) + currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, VariableType.array.rawValue, stringConstantName, key, .emptyArray)) } else { let subClassType = value.arrayValue.first!.detailedValueType() - if subClassType == .Object { + if subClassType == .object { let models = generateModelForJSON(JSONHelper.reduce(value.arrayValue), variableName, false) - modelFiles = modelFiles + models + modelFiles += models let model = models.first let classname = model?.fileName - currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, classname!, stringConstantName, key, .ObjectTypeArray)) + currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, classname!, stringConstantName, key, .objectTypeArray)) } else { - currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, subClassType.rawValue, stringConstantName, key, .ValueTypeArray)) + currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, subClassType.rawValue, stringConstantName, key, .valueTypeArray)) } } - case .Object: + case .object: let models = generateModelForJSON(value, variableName, false) let model = models.first let typeName = model?.fileName - currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, typeName!, stringConstantName, key, .ObjectType)) - modelFiles = modelFiles + models - case .Null: - currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, VariableType.Null.rawValue, stringConstantName, key, .NullType)) + currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, typeName!, stringConstantName, key, .objectType)) + modelFiles += models + case .null: + currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, VariableType.null.rawValue, stringConstantName, key, .nullType)) break default: - currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, variableType.rawValue, stringConstantName, key, .ValueType)) + currentModel.generateAndAddComponentsFor(PropertyComponent.init(variableName, variableType.rawValue, stringConstantName, key, .valueType)) } } @@ -141,11 +141,11 @@ public struct ModelGenerator { */ func initialiseModelFileFor(_ modelMappingLibrary: JSONMappingLibrary) -> ModelFile { switch modelMappingLibrary { - case .ObjectMapper: + case .libObjectMapper: return ObjectMapperModelFile() - case .SwiftyJSON: + case .libSwiftyJSON: return SwiftyJSONModelFile() - case .Marshal: + case .libMarshal: return MarshalModelFile() } } diff --git a/Core/Generators/MultipleModelGenerator.swift b/Core/Generators/MultipleModelGenerator.swift index 80d9f2d..ca52cc3 100644 --- a/Core/Generators/MultipleModelGenerator.swift +++ b/Core/Generators/MultipleModelGenerator.swift @@ -107,13 +107,13 @@ struct MultipleModelGenerator { var basePath = fromBasePath if basePath.hasSuffix("/") == false { - basePath = basePath + "/" + basePath += "/" } finalPath = basePath + destinationPath } if finalPath.hasSuffix("/") == false { - finalPath = finalPath + "/" + finalPath += "/" } return finalPath } @@ -145,16 +145,16 @@ struct MultipleModelGenerator { /// - Returns: Configuration model. /// - Throws: `MultipleModelGeneratorError.configInvalid` error. static func loadConfiguration(fromJSON: JSON) throws -> ModelGenerationConfiguration? { - var constructType = ConstructType.ClassType + var constructType = ConstructType.classType if let type = fromJSON["construct_type"].string, type == "struct" { - constructType = ConstructType.StructType + constructType = ConstructType.structType } - var jsonLibrary = JSONMappingLibrary.SwiftyJSON + var jsonLibrary = JSONMappingLibrary.libSwiftyJSON if let type = fromJSON["model_mapping_library"].string { - if type == JSONMappingLibrary.ObjectMapper.rawValue { - jsonLibrary = JSONMappingLibrary.ObjectMapper - } else if type == JSONMappingLibrary.Marshal.rawValue { - jsonLibrary = JSONMappingLibrary.Marshal + if type == JSONMappingLibrary.libObjectMapper.rawValue { + jsonLibrary = JSONMappingLibrary.libObjectMapper + } else if type == JSONMappingLibrary.libMarshal.rawValue { + jsonLibrary = JSONMappingLibrary.libMarshal } } let config = ModelGenerationConfiguration.init(filePath: fromJSON["destination_path"].string ?? "", @@ -213,12 +213,9 @@ struct MultipleModelGenerator { let m = ModelGenerator.init(combinedJSON, (models.first?.configuration)!) let newModels = m.generateModelForJSON(combinedJSON, fileName, false) - for newModel in newModels { - // We only care about the current model file, all sub models will be merged on their own. - if newModel.fileName == (models.first?.fileName)! { - modelsToReturn.append(newModel) - break - } + for newModel in newModels where newModel.fileName == (models.first?.fileName)! { + modelsToReturn.append(newModel) + break } } } diff --git a/Core/Helpers/JSON+Helpers.swift b/Core/Helpers/JSON+Helpers.swift index c8f16bd..c6f17c2 100644 --- a/Core/Helpers/JSON+Helpers.swift +++ b/Core/Helpers/JSON+Helpers.swift @@ -19,11 +19,11 @@ extension JSON { func detailedValueType() -> VariableType { switch self.type { case .string: - return VariableType.String + return VariableType.string case .bool: - return VariableType.Bool + return VariableType.bool case .array: - return VariableType.Array + return VariableType.array case .number: switch CFNumberGetType(self.numberValue as CFNumber) { case .sInt8Type, @@ -37,18 +37,18 @@ extension JSON { .longLongType, .cfIndexType, .nsIntegerType: - return VariableType.Int + return VariableType.int case .float32Type, .float64Type, .floatType, .cgFloatType, .doubleType: - return VariableType.Float + return VariableType.float } case .null: - return VariableType.Null + return VariableType.null default: - return VariableType.Object + return VariableType.object } } } diff --git a/Core/Library-Extensions/FileGeneratorExtension.swift b/Core/Library-Extensions/FileGeneratorExtension.swift index 0b4b8ec..1936174 100644 --- a/Core/Library-Extensions/FileGeneratorExtension.swift +++ b/Core/Library-Extensions/FileGeneratorExtension.swift @@ -19,7 +19,7 @@ extension FileGenerator { content = content.replacingOccurrences(of: "{OBJECT_KIND}", with: modelFile.type.rawValue) content = content.replacingOccurrences(of: "{JSON_PARSER_LIBRARY_BODY}", with: loadFileWith(modelFile.mainBodyTemplateFileName())) - if modelFile.type == .ClassType { + if modelFile.type == .classType { content = content.replacingOccurrences(of: "{REQUIRED}", with: " required ") } else { content = content.replacingOccurrences(of: "{REQUIRED}", with: " ") @@ -40,11 +40,11 @@ extension FileGenerator { if let extendFrom = modelFile.baseElementName() { classesExtendFrom = [extendFrom] } - if configuration.supportNSCoding && configuration.constructType == .ClassType { - classesExtendFrom = classesExtendFrom + ["NSCoding"] + if configuration.supportNSCoding && configuration.constructType == .classType { + classesExtendFrom += ["NSCoding"] } - if configuration.isFinalRequired && configuration.constructType == .ClassType { + if configuration.isFinalRequired && configuration.constructType == .classType { content = content.replacingOccurrences(of: "{IS_FINAL}", with: " final ") } else { content = content.replacingOccurrences(of: "{IS_FINAL}", with: " ") @@ -68,11 +68,11 @@ extension FileGenerator { content = content.replacingOccurrences(of: "{INITIALIZER}", with: initialisers) content = content.replacingOccurrences(of: "{DESCRIPTION}", with: description) - if configuration.constructType == .StructType { + if configuration.constructType == .structType { content = content.replacingOccurrences(of: " convenience", with: "") } - if configuration.supportNSCoding && configuration.constructType == .ClassType { + if configuration.supportNSCoding && configuration.constructType == .classType { content = content.replacingOccurrences(of: "{NSCODING_SUPPORT}", with: loadFileWith("NSCodingTemplate")) let encoders = modelFile.component.encoders.map({ doubleTab + $0 }).joined(separator: "\n") let decoders = modelFile.component.decoders.map({ doubleTab + $0 }).joined(separator: "\n") diff --git a/Core/Library-Extensions/MarshalModelFile.swift b/Core/Library-Extensions/MarshalModelFile.swift index 64bfe04..37d1392 100644 --- a/Core/Library-Extensions/MarshalModelFile.swift +++ b/Core/Library-Extensions/MarshalModelFile.swift @@ -19,7 +19,7 @@ struct MarshalModelFile: ModelFile, DefaultModelFileComponent { init() { self.fileName = "" - type = ConstructType.StructType + type = ConstructType.structType component = ModelComponent.init() sourceJSON = JSON.init([]) } @@ -45,38 +45,38 @@ struct MarshalModelFile: ModelFile, DefaultModelFileComponent { mutating func generateAndAddComponentsFor(_ property: PropertyComponent) { switch property.propertyType { - case .ValueType: + case .valueType: component.declarations.append(genVariableDeclaration(property.name, property.type, false)) component.description.append(genDescriptionForPrimitive(property.name, property.type, property.constantName)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, false)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) generateCommonComponentsFor(property) - case .ValueTypeArray: + case .valueTypeArray: component.description.append(genDescriptionForPrimitiveArray(property.name, property.constantName)) component.declarations.append(genVariableDeclaration(property.name, property.type, true)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, true)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) generateCommonComponentsFor(property) - case .ObjectType: + case .objectType: component.description.append(genDescriptionForObject(property.name, property.constantName)) component.declarations.append(genVariableDeclaration(property.name, property.type, false)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, false)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) generateCommonComponentsFor(property) - case .ObjectTypeArray: + case .objectTypeArray: component.declarations.append(genVariableDeclaration(property.name, property.type, true)) component.description.append(genDescriptionForObjectArray(property.name, property.constantName)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, true)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) generateCommonComponentsFor(property) - case .EmptyArray: + case .emptyArray: component.declarations.append(genVariableDeclaration(property.name, "Any", true)) component.description.append(genDescriptionForPrimitiveArray(property.name, property.constantName)) component.decoders.append(genDecoder(property.name, "Any", property.constantName, true)) component.encoders.append(genEncoder(property.name, "Any", property.constantName)) generateCommonComponentsFor(property) - case .NullType: break + case .nullType: break // Currently we do not deal with null values. } diff --git a/Core/Library-Extensions/ObjectMapperModelFile.swift b/Core/Library-Extensions/ObjectMapperModelFile.swift index 5572497..2abb84b 100644 --- a/Core/Library-Extensions/ObjectMapperModelFile.swift +++ b/Core/Library-Extensions/ObjectMapperModelFile.swift @@ -19,7 +19,7 @@ struct ObjectMapperModelFile: ModelFile, DefaultModelFileComponent { init() { self.fileName = "" - type = ConstructType.StructType + type = ConstructType.structType component = ModelComponent.init() sourceJSON = JSON.init([]) } @@ -45,38 +45,38 @@ struct ObjectMapperModelFile: ModelFile, DefaultModelFileComponent { mutating func generateAndAddComponentsFor(_ property: PropertyComponent) { switch property.propertyType { - case .ValueType: + case .valueType: component.declarations.append(genVariableDeclaration(property.name, property.type, false)) component.description.append(genDescriptionForPrimitive(property.name, property.type, property.constantName)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, false)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) generateCommonComponentsFor(property) - case .ValueTypeArray: + case .valueTypeArray: component.description.append(genDescriptionForPrimitiveArray(property.name, property.constantName)) component.declarations.append(genVariableDeclaration(property.name, property.type, true)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, true)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) generateCommonComponentsFor(property) - case .ObjectType: + case .objectType: component.description.append(genDescriptionForObject(property.name, property.constantName)) component.declarations.append(genVariableDeclaration(property.name, property.type, false)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, false)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) generateCommonComponentsFor(property) - case .ObjectTypeArray: + case .objectTypeArray: component.declarations.append(genVariableDeclaration(property.name, property.type, true)) component.description.append(genDescriptionForObjectArray(property.name, property.constantName)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, true)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) generateCommonComponentsFor(property) - case .EmptyArray: + case .emptyArray: component.declarations.append(genVariableDeclaration(property.name, "Any", true)) component.description.append(genDescriptionForPrimitiveArray(property.name, property.constantName)) component.decoders.append(genDecoder(property.name, "Any", property.constantName, true)) component.encoders.append(genEncoder(property.name, "Any", property.constantName)) generateCommonComponentsFor(property) - case .NullType: break + case .nullType: break // Currently we do not deal with null values. } diff --git a/Core/Library-Extensions/SwiftyJSONModelFile.swift b/Core/Library-Extensions/SwiftyJSONModelFile.swift index 0ffde90..6b0418d 100644 --- a/Core/Library-Extensions/SwiftyJSONModelFile.swift +++ b/Core/Library-Extensions/SwiftyJSONModelFile.swift @@ -22,7 +22,7 @@ struct SwiftyJSONModelFile: ModelFile, DefaultModelFileComponent { // MARK: - Initialisers. init() { self.fileName = "" - type = ConstructType.StructType + type = ConstructType.structType component = ModelComponent.init() sourceJSON = JSON.init([]) } @@ -47,42 +47,42 @@ struct SwiftyJSONModelFile: ModelFile, DefaultModelFileComponent { mutating func generateAndAddComponentsFor(_ property: PropertyComponent) { switch property.propertyType { - case .ValueType: + case .valueType: component.stringConstants.append(genStringConstant(property.constantName, property.key)) component.initialisers.append(genInitializerForVariable(property.name, property.type, property.constantName)) component.declarations.append(genVariableDeclaration(property.name, property.type, false)) component.description.append(genDescriptionForPrimitive(property.name, property.type, property.constantName)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, false)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) - case .ValueTypeArray: + case .valueTypeArray: component.stringConstants.append(genStringConstant(property.constantName, property.key)) component.initialisers.append(genInitializerForPrimitiveArray(property.name, property.type, property.constantName)) component.declarations.append(genVariableDeclaration(property.name, property.type, true)) component.description.append(genDescriptionForPrimitiveArray(property.name, property.constantName)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, true)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) - case .ObjectType: + case .objectType: component.stringConstants.append(genStringConstant(property.constantName, property.key)) component.initialisers.append(genInitializerForObject(property.name, property.type, property.constantName)) component.declarations.append(genVariableDeclaration(property.name, property.type, false)) component.description.append(genDescriptionForObject(property.name, property.constantName)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, false)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) - case .ObjectTypeArray: + case .objectTypeArray: component.stringConstants.append(genStringConstant(property.constantName, property.key)) component.initialisers.append(genInitializerForObjectArray(property.name, property.type, property.constantName)) component.declarations.append(genVariableDeclaration(property.name, property.type, true)) component.description.append(genDescriptionForObjectArray(property.name, property.constantName)) component.decoders.append(genDecoder(property.name, property.type, property.constantName, true)) component.encoders.append(genEncoder(property.name, property.type, property.constantName)) - case .EmptyArray: + case .emptyArray: component.stringConstants.append(genStringConstant(property.constantName, property.key)) component.initialisers.append(genInitializerForPrimitiveArray(property.name, "object", property.constantName)) component.declarations.append(genVariableDeclaration(property.name, "Any", true)) component.description.append(genDescriptionForPrimitiveArray(property.name, property.constantName)) component.decoders.append(genDecoder(property.name, "Any", property.constantName, true)) component.encoders.append(genEncoder(property.name, "Any", property.constantName)) - case .NullType: + case .nullType: // Currently we do not deal with null values. break } @@ -93,7 +93,7 @@ struct SwiftyJSONModelFile: ModelFile, DefaultModelFileComponent { func genInitializerForVariable(_ name: String, _ type: String, _ constantName: String) -> String { var variableType = type variableType.lowerCaseFirst() - if type == VariableType.Bool.rawValue { + if type == VariableType.bool.rawValue { return "\(name) = json[\(constantName)].\(variableType)Value" } return "\(name) = json[\(constantName)].\(variableType)" diff --git a/Core/Models-Components/DefaultModelFileComponent.swift b/Core/Models-Components/DefaultModelFileComponent.swift index 7f48681..017561d 100644 --- a/Core/Models-Components/DefaultModelFileComponent.swift +++ b/Core/Models-Components/DefaultModelFileComponent.swift @@ -130,14 +130,14 @@ extension DefaultModelFileComponent { } func genPrimitiveVariableDeclaration(_ name: String, _ type: String) -> String { - if type == VariableType.Bool.rawValue { + if type == VariableType.bool.rawValue { return "public var \(name): \(type)? = false" } return "public var \(name): \(type)?" } func genDescriptionForPrimitive(_ name: String, _ type: String, _ constantName: String) -> String { - if type == VariableType.Bool.rawValue { + if type == VariableType.bool.rawValue { return "dictionary[\(constantName)] = \(name)" } return "if let value = \(name) { dictionary[\(constantName)] = value }" @@ -155,7 +155,7 @@ extension DefaultModelFileComponent { } func genEncoder(_ name: String, _ type: String, _ constantName: String) -> String { - if type == VariableType.Bool.rawValue { + if type == VariableType.bool.rawValue { return "aCoder.encode(\(name), forKey: \(constantName))" } return "aCoder.encode(\(name), forKey: \(constantName))" @@ -163,7 +163,7 @@ extension DefaultModelFileComponent { func genDecoder(_ name: String, _ type: String, _ constantName: String, _ isArray: Bool) -> String { let finalTypeName = isArray ? "[\(type)]" : type - if type == VariableType.Bool.rawValue { + if type == VariableType.bool.rawValue { return "self.\(name) = aDecoder.decodeBool(forKey: \(constantName))" } return "self.\(name) = aDecoder.decodeObject(forKey: \(constantName)) as? \(finalTypeName)" diff --git a/Core/Models-Components/ModelGenerationConfiguration.swift b/Core/Models-Components/ModelGenerationConfiguration.swift index f4f1669..6b473fa 100644 --- a/Core/Models-Components/ModelGenerationConfiguration.swift +++ b/Core/Models-Components/ModelGenerationConfiguration.swift @@ -37,7 +37,7 @@ struct ModelGenerationConfiguration { /// /// - Returns: If the config is valid and the reason for invalidation if it is invalid. func isConfigurationValid() -> (isValid: Bool, reason: String) { - if constructType == .StructType && (isFinalRequired == true || supportNSCoding == true) { + if constructType == .structType && (isFinalRequired == true || supportNSCoding == true) { return (false, "Struct cannot have final or NSCoding support, only applicable to class.") } return (true, "") @@ -47,8 +47,8 @@ struct ModelGenerationConfiguration { isHeaderIncluded = true isFinalRequired = true supportNSCoding = true - modelMappingLibrary = .SwiftyJSON - constructType = .ClassType + modelMappingLibrary = .libSwiftyJSON + constructType = .classType prefix = "" filePath = "" baseClassName = "" diff --git a/SwiftyJSONAccelerator/Storyboard/Main.storyboard b/SwiftyJSONAccelerator/Storyboard/Main.storyboard index 90427d0..bffc272 100644 --- a/SwiftyJSONAccelerator/Storyboard/Main.storyboard +++ b/SwiftyJSONAccelerator/Storyboard/Main.storyboard @@ -3,7 +3,6 @@ - @@ -314,35 +313,22 @@ - - + + - - - + + - + - + - + @@ -354,39 +340,16 @@ - + - - - - - - - - - - + + - + + - - - - - - - - - - - - - - - - @@ -394,7 +357,11 @@ - + + + + + @@ -402,19 +369,24 @@ - + + + + + - - - - - + + + + + + @@ -431,12 +403,16 @@ - + + + + + - - + + @@ -444,34 +420,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + diff --git a/SwiftyJSONAccelerator/Support/Info.plist b/SwiftyJSONAccelerator/Support/Info.plist index 906cb1b..51a9339 100644 --- a/SwiftyJSONAccelerator/Support/Info.plist +++ b/SwiftyJSONAccelerator/Support/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.4.0 + 1.5.0 CFBundleSignature ???? CFBundleVersion - 10 + 11 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/SwiftyJSONAccelerator/UI/SJEditorViewController.swift b/SwiftyJSONAccelerator/UI/SJEditorViewController.swift index 59c04b1..d3aa71c 100644 --- a/SwiftyJSONAccelerator/UI/SJEditorViewController.swift +++ b/SwiftyJSONAccelerator/UI/SJEditorViewController.swift @@ -33,7 +33,6 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { // MARK: Outlet files. @IBOutlet var textView: SJTextView! - @IBOutlet var messageLabel: NSTextField! @IBOutlet var errorImageView: NSImageView! @IBOutlet var baseClassTextField: NSTextField! @IBOutlet var prefixClassTextField: NSTextField! @@ -150,7 +149,7 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { let nsCodingState = self.enableNSCodingSupportCheckbox.state == 1 && (modelTypeSelectorSegment.selectedSegment == 1) let isFinalClass = self.setAsFinalCheckbox.state == 1 && (modelTypeSelectorSegment.selectedSegment == 1) - let constructType = self.modelTypeSelectorSegment.selectedSegment == 0 ? ConstructType.StructType : ConstructType.ClassType + let constructType = self.modelTypeSelectorSegment.selectedSegment == 0 ? ConstructType.structType : ConstructType.classType let libraryType = libraryForIndex(self.librarySelector.indexOfSelectedItem) let configuration = ModelGenerationConfiguration.init( filePath: filePath!.appending("/"), @@ -188,11 +187,11 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { func libraryForIndex(_ index: Int) -> JSONMappingLibrary { if index == 2 { - return JSONMappingLibrary.ObjectMapper + return JSONMappingLibrary.libObjectMapper } else if index == 3 { - return JSONMappingLibrary.Marshal + return JSONMappingLibrary.libMarshal } - return JSONMappingLibrary.SwiftyJSON + return JSONMappingLibrary.libSwiftyJSON } @IBAction func recalcEnabledBoxes(_ sender: AnyObject) { @@ -289,7 +288,6 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { */ func resetErrorImage() { errorImageView?.image = nil - messageLabel?.stringValue = "" } /** @@ -297,7 +295,6 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { */ func correctJSONMessage() { errorImageView?.image = NSImage.init(named: "success") - messageLabel?.stringValue = "Valid JSON!" } /** @@ -308,7 +305,6 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate { */ func invalidJSONError(_ message: String) { errorImageView?.image = NSImage.init(named: "failure") - messageLabel?.stringValue = message } // MARK: TextView Delegate diff --git a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift index 39d6180..4f0d99d 100644 --- a/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift +++ b/SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift @@ -64,7 +64,7 @@ class ModelGeneratorTests: XCTestCase { authorName: "Jane Smith", companyName: "Acme Co.", prefix: "AC", - constructType: .StructType, + constructType: .structType, modelMappingLibrary: library, supportNSCoding: true, isFinalRequired: true, @@ -75,19 +75,19 @@ class ModelGeneratorTests: XCTestCase { Test model file initialisation test. */ func testinitialiseModelFileFor() { - let config = defaultConfiguration(.SwiftyJSON) + let config = defaultConfiguration(.libSwiftyJSON) let m = ModelGenerator.init(JSON.init([testJSON()]), config) - expect(m.initialiseModelFileFor(.SwiftyJSON) is SwiftyJSONModelFile).to(equal(true)) - expect(m.initialiseModelFileFor(.SwiftyJSON) is ObjectMapperModelFile).to(equal(false)) - expect(m.initialiseModelFileFor(.ObjectMapper) is SwiftyJSONModelFile).to(equal(false)) - expect(m.initialiseModelFileFor(.ObjectMapper) is ObjectMapperModelFile).to(equal(true)) + expect(m.initialiseModelFileFor(.libSwiftyJSON) is SwiftyJSONModelFile).to(equal(true)) + expect(m.initialiseModelFileFor(.libSwiftyJSON) is ObjectMapperModelFile).to(equal(false)) + expect(m.initialiseModelFileFor(.libObjectMapper) is SwiftyJSONModelFile).to(equal(false)) + expect(m.initialiseModelFileFor(.libObjectMapper) is ObjectMapperModelFile).to(equal(true)) } /** Test notifications to be generated for the given files. */ func testNotifications() { - let config = defaultConfiguration(.SwiftyJSON) + let config = defaultConfiguration(.libSwiftyJSON) let m = ModelGenerator.init(JSON.init([testJSON()]), config) let files = m.generate() let errorNotification = m.generateNotificationFor([]) @@ -103,7 +103,7 @@ class ModelGeneratorTests: XCTestCase { Test for invalid JSON. */ func testSwiftyJSONForInvalidJSON() { - let config = defaultConfiguration(.SwiftyJSON) + let config = defaultConfiguration(.libSwiftyJSON) let m = ModelGenerator.init(JSON.init(["hello!"]), config) let files = m.generate() expect(files.count).to(equal(0)) @@ -113,7 +113,7 @@ class ModelGeneratorTests: XCTestCase { Generate files for JSON which is an array. */ func testSwiftyJSONModelWithRootAsArray() { - let config = defaultConfiguration(.SwiftyJSON) + let config = defaultConfiguration(.libSwiftyJSON) let m = ModelGenerator.init(JSON.init([testJSON()]), config) let files = m.generate() expect(files.count).to(equal(4)) @@ -140,7 +140,7 @@ class ModelGeneratorTests: XCTestCase { Generate and test the files generated for SwiftyJSON value. */ func testSwiftyJSONModel() { - let config = defaultConfiguration(.SwiftyJSON) + let config = defaultConfiguration(.libSwiftyJSON) let m = ModelGenerator.init(testJSON(), config) let files = m.generate() runCheckForBaseModel(files, config, runSwiftyJSONInitialiserCheckForBaseModel(_:)) @@ -162,7 +162,7 @@ class ModelGeneratorTests: XCTestCase { Generate and test the files generated for ObjectMapper value. */ func testObjectMapperModel() { - let config = defaultConfiguration(.ObjectMapper) + let config = defaultConfiguration(.libObjectMapper) let m = ModelGenerator.init(testJSON(), config) let files = m.generate() runCheckForBaseModel(files, config, runObjectMapperInitialiserCheckForBaseModel(_:)) @@ -183,7 +183,7 @@ class ModelGeneratorTests: XCTestCase { Generate and test the files generated for Marshal value. */ func testMarshalModel() { - let config = defaultConfiguration(.Marshal) + let config = defaultConfiguration(.libMarshal) let m = ModelGenerator.init(testJSON(), config) let files = m.generate() runCheckForBaseModel(files, config, runMarshalInitialiserCheckForBaseModel(_:)) @@ -210,8 +210,8 @@ class ModelGeneratorTests: XCTestCase { authorName: "Jane Smith", companyName: "Acme Co.", prefix: "AC", - constructType: .ClassType, - modelMappingLibrary: .Marshal, + constructType: .classType, + modelMappingLibrary: .libMarshal, supportNSCoding: true, isFinalRequired: true, isHeaderIncluded: true) From 1207b39feab94ef7abf305ff7bbe8368da0bb481 Mon Sep 17 00:00:00 2001 From: Karthikeya Udupa Date: Wed, 24 Jul 2019 12:51:39 +0200 Subject: [PATCH 2/2] fix: now able to build the project again and migrated to swift 5 --- .swiftlint.yml | 1 + Core/Generators/NameGenerator.swift | 8 ++--- Core/Helpers/String+Helpers.swift | 6 ++-- README.md | 11 ++++++ .../project.pbxproj | 21 ++++++----- .../LineNumberRulerView.swift | 20 ++++++----- .../Storyboard/Main.storyboard | 34 +++++++++--------- .../UI/SJEditorViewController.swift | 19 +++++----- SwiftyJSONAccelerator/UI/SJTextView.swift | 4 +-- preview-dark-mode.png | Bin 0 -> 117488 bytes 10 files changed, 71 insertions(+), 53 deletions(-) create mode 100644 preview-dark-mode.png diff --git a/.swiftlint.yml b/.swiftlint.yml index bd8eaab..c4925d9 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -4,6 +4,7 @@ disabled_rules: # rule identifiers to exclude from running - unused_closure_parameter - valid_docs - large_tuple + - identifier_name excluded: # paths to ignore during linting. Takes precedence over `included`. - SwiftyJSONAcceleratorTests - Pods diff --git a/Core/Generators/NameGenerator.swift b/Core/Generators/NameGenerator.swift index 16e4b0b..581de0e 100644 --- a/Core/Generators/NameGenerator.swift +++ b/Core/Generators/NameGenerator.swift @@ -44,12 +44,12 @@ struct NameGenerator { */ static func fixVariableName(_ variableName: String) -> String { - var _variableName = replaceKeywords(variableName) - _variableName.replaceOccurrencesOfStringsWithString(["-", "_"], " ") - _variableName.trim() + var tmpVariableName = replaceKeywords(variableName) + tmpVariableName.replaceOccurrencesOfStringsWithString(["-", "_"], " ") + tmpVariableName.trim() var finalVariableName = "" - for (index, var element) in _variableName.components(separatedBy: " ").enumerated() { + for (index, var element) in tmpVariableName.components(separatedBy: " ").enumerated() { index == 0 ? element.lowerCaseFirst() : element.uppercaseFirst() finalVariableName.append(element) } diff --git a/Core/Helpers/String+Helpers.swift b/Core/Helpers/String+Helpers.swift index a313708..d4ceaae 100644 --- a/Core/Helpers/String+Helpers.swift +++ b/Core/Helpers/String+Helpers.swift @@ -13,21 +13,21 @@ extension String { /// Fetches the first character of the string. var first: String { - return String(characters.prefix(1)) + return String(self.prefix(1)) } /** Makes the first character upper case. */ mutating func uppercaseFirst() { - self = first.uppercased() + String(characters.dropFirst()) + self = first.uppercased() + String(self.dropFirst()) } /** Makes the first character lowercase. */ mutating func lowerCaseFirst() { - self = first.lowercased() + String(characters.dropFirst()) + self = first.lowercased() + String(self.dropFirst()) } /** diff --git a/README.md b/README.md index bc2074b..50130e1 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,17 @@ [![Build Status](https://travis-ci.org/insanoid/SwiftyJSONAccelerator.svg?branch=master)](https://travis-ci.org/insanoid/SwiftyJSONAccelerator) [![codecov](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator/branch/master/graph/badge.svg)](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator) +**Version v1.4.0 Released! (Swift 3 Last Legacy Version)** + +- This is a compatibility release for people using Swift 3 still to make sure the project still works. +- Code was updated to Swift 5 to make it work, however, tests are broken due to Nimble compatibility. +- This will be the last legacy version for this project, it will only generate `swift 5` `codable` format from next version onwards (branch `swift-5`). +- Supports dark mode :| + +![Preview](https://github.com/insanoid/SwiftyJSONAccelerator/raw/master/preview-dark-mode.png) + +- **Application Download:** [Download the .app (v1.5.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v1.5.0/SwiftyJSONAccelerator.zip) + **Version v1.4.0 Released!** - Generate models from multiple JSON files in a folder at with one click! diff --git a/SwiftyJSONAccelerator.xcodeproj/project.pbxproj b/SwiftyJSONAccelerator.xcodeproj/project.pbxproj index 2430d74..c29d55a 100644 --- a/SwiftyJSONAccelerator.xcodeproj/project.pbxproj +++ b/SwiftyJSONAccelerator.xcodeproj/project.pbxproj @@ -71,7 +71,6 @@ 937245531E12ED4A005387E8 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937245521E12ED4A005387E8 /* SwiftyJSON.swift */; }; 937245541E12ED4D005387E8 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937245521E12ED4A005387E8 /* SwiftyJSON.swift */; }; 937245551E12ED4D005387E8 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937245521E12ED4A005387E8 /* SwiftyJSON.swift */; }; - 937245581E12EE37005387E8 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 937245571E12EE37005387E8 /* Nimble.framework */; }; 9380E5941D2C6D12003F77B1 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9380E5931D2C6D12003F77B1 /* StringTests.swift */; }; 9395707B1D008A860039453D /* DefaultModelFileComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9395707A1D008A860039453D /* DefaultModelFileComponent.swift */; }; 93C273CB1E150CEA00CC1AED /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 93C273CA1E150CEA00CC1AED /* Main.storyboard */; }; @@ -95,6 +94,7 @@ 93D850EF1D00D3070023D573 /* ObjectMapperModelFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F1593F1CFF96E700175636 /* ObjectMapperModelFile.swift */; }; 93D850F01D00D3070023D573 /* DefaultModelFileComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9395707A1D008A860039453D /* DefaultModelFileComponent.swift */; }; 93D850F71D00D7C80023D573 /* TestJSONFile.sample in Resources */ = {isa = PBXBuildFile; fileRef = 93D850F61D00D7C80023D573 /* TestJSONFile.sample */; }; + 93E0F12622E8674D008D3B16 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93E0F12522E8674D008D3B16 /* Nimble.framework */; }; 93E91B0D1CFF2DFF00ECA2A6 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93E91B0C1CFF2DFF00ECA2A6 /* Constants.swift */; }; 93F1592C1CFF826900175636 /* ModelGenerationConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F1592B1CFF826900175636 /* ModelGenerationConfiguration.swift */; }; 93F159301CFF832100175636 /* ModelFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F1592F1CFF832100175636 /* ModelFile.swift */; }; @@ -169,6 +169,7 @@ 93C273CA1E150CEA00CC1AED /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 93CDE7711BD1A00B00B5B234 /* SJTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SJTextView.swift; sourceTree = ""; }; 93D850F61D00D7C80023D573 /* TestJSONFile.sample */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TestJSONFile.sample; sourceTree = ""; }; + 93E0F12522E8674D008D3B16 /* Nimble.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Nimble.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 93E91B0C1CFF2DFF00ECA2A6 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; 93F1592B1CFF826900175636 /* ModelGenerationConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModelGenerationConfiguration.swift; sourceTree = ""; }; 93F1592F1CFF832100175636 /* ModelFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModelFile.swift; sourceTree = ""; }; @@ -210,7 +211,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 937245581E12EE37005387E8 /* Nimble.framework in Frameworks */, + 93E0F12622E8674D008D3B16 /* Nimble.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -350,6 +351,7 @@ 937245561E12EE37005387E8 /* Frameworks */ = { isa = PBXGroup; children = ( + 93E0F12522E8674D008D3B16 /* Nimble.framework */, 937245571E12EE37005387E8 /* Nimble.framework */, ); name = Frameworks; @@ -554,6 +556,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -617,7 +620,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -750,7 +753,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) '@executable_path/../Frameworks' '@loader_path/Frameworks' @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -765,7 +768,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) '@executable_path/../Frameworks' '@loader_path/Frameworks' @executable_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -873,7 +876,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = com.karthik.SwiftyJSONAccelerator; PRODUCT_NAME = SwiftyJSONAccelerator; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -890,7 +893,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = com.karthik.SwiftyJSONAccelerator; PRODUCT_NAME = SwiftyJSONAccelerator; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -905,7 +908,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.karthik.SwiftyJSONAcceleratorTests; PRODUCT_NAME = SwiftyJSONAccelerator; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftyJSONAccelerator.app/Contents/MacOS/SwiftyJSONAccelerator"; }; name = Debug; @@ -921,7 +924,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.karthik.SwiftyJSONAcceleratorTests; PRODUCT_NAME = SwiftyJSONAccelerator; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftyJSONAccelerator.app/Contents/MacOS/SwiftyJSONAccelerator"; }; name = Release; diff --git a/SwiftyJSONAccelerator/External-Libraries/LineNumberRulerView.swift b/SwiftyJSONAccelerator/External-Libraries/LineNumberRulerView.swift index 3e39088..b1d5c94 100755 --- a/SwiftyJSONAccelerator/External-Libraries/LineNumberRulerView.swift +++ b/SwiftyJSONAccelerator/External-Libraries/LineNumberRulerView.swift @@ -53,16 +53,18 @@ extension NSTextView { } postsFrameChangedNotifications = true - NotificationCenter.default.addObserver(self, selector: #selector(NSTextView.lnv_framDidChange(_:)), name: NSNotification.Name.NSViewFrameDidChange, object: self) - NotificationCenter.default.addObserver(self, selector: #selector(NSTextView.lnv_textDidChange(_:)), name: NSNotification.Name.NSTextDidChange, object: self) + + + NotificationCenter.default.addObserver(self, selector: #selector(NSTextView.lnv_framDidChange(_:)), name: NSView.frameDidChangeNotification, object: self) + NotificationCenter.default.addObserver(self, selector: #selector(NSTextView.lnv_textDidChange(_:)), name: NSText.didChangeNotification, object: self) } - func lnv_framDidChange(_ notification: Notification) { + @objc func lnv_framDidChange(_ notification: Notification) { lineNumberView.needsDisplay = true } - func lnv_textDidChange(_ notification: Notification) { + @objc func lnv_textDidChange(_ notification: Notification) { lineNumberView.needsDisplay = true } @@ -78,8 +80,8 @@ class LineNumberRulerView: NSRulerView { } init(textView: NSTextView) { - super.init(scrollView: textView.enclosingScrollView!, orientation: NSRulerOrientation.verticalRuler) - self.font = textView.font ?? NSFont.systemFont(ofSize: NSFont.smallSystemFontSize()) + super.init(scrollView: textView.enclosingScrollView!, orientation: NSRulerView.Orientation.verticalRuler) + self.font = textView.font ?? NSFont.systemFont(ofSize: NSFont.smallSystemFontSize) self.clientView = textView self.ruleThickness = 40 @@ -95,7 +97,7 @@ class LineNumberRulerView: NSRulerView { if let layoutManager = textView.layoutManager { let relativePoint = self.convert(NSZeroPoint, from: textView) - let lineNumberAttributes = [NSFontAttributeName: textView.font!, NSForegroundColorAttributeName: NSColor.gray] as [String : Any] + let lineNumberAttributes = [NSAttributedString.Key.font.rawValue: textView.font!, NSAttributedString.Key.foregroundColor: NSColor.gray] as! [NSAttributedString.Key : Any] let drawLineNumber = { (lineNumberString: String, y: CGFloat) -> Void in let attString = NSAttributedString(string: lineNumberString, attributes: lineNumberAttributes) let x = 35 - attString.size().width @@ -107,7 +109,7 @@ class LineNumberRulerView: NSRulerView { let newLineRegex = try! NSRegularExpression(pattern: "\n", options: []) // The line number for the first visible line - var lineNumber = newLineRegex.numberOfMatches(in: textView.string!, options: [], range: NSMakeRange(0, firstVisibleGlyphCharacterIndex)) + 1 + var lineNumber = newLineRegex.numberOfMatches(in: textView.string, options: [], range: NSMakeRange(0, firstVisibleGlyphCharacterIndex)) + 1 var glyphIndexForStringLine = visibleGlyphRange.location @@ -115,7 +117,7 @@ class LineNumberRulerView: NSRulerView { while glyphIndexForStringLine < NSMaxRange(visibleGlyphRange) { // Range of current line in the string. - let characterRangeForStringLine = (textView.string! as NSString).lineRange( + let characterRangeForStringLine = (textView.string as NSString).lineRange( for: NSMakeRange(layoutManager.characterIndexForGlyph(at: glyphIndexForStringLine), 0) ) let glyphRangeForStringLine = layoutManager.glyphRange(forCharacterRange: characterRangeForStringLine, actualCharacterRange: nil) diff --git a/SwiftyJSONAccelerator/Storyboard/Main.storyboard b/SwiftyJSONAccelerator/Storyboard/Main.storyboard index bffc272..4f64cbe 100644 --- a/SwiftyJSONAccelerator/Storyboard/Main.storyboard +++ b/SwiftyJSONAccelerator/Storyboard/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -323,11 +323,11 @@ - + - - + + @@ -335,16 +335,16 @@ -