Skip to content

Commit e5e247b

Browse files
authored
Merge pull request #94 from insanoid/swift-5
Swift 5
2 parents 63ebd35 + 299df1d commit e5e247b

89 files changed

Lines changed: 2346 additions & 4365 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitmodules

Lines changed: 0 additions & 9 deletions
This file was deleted.

.slather.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.0

.swiftformat

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# file options
2+
3+
--exclude Tests/XCTestManifests.swift,Snapshots
4+
5+
# format options
6+
7+
--allman false
8+
--binarygrouping 4,8
9+
--commas always
10+
--comments indent
11+
--decimalgrouping 3,6
12+
--elseposition same-line
13+
--empty void
14+
--exponentcase lowercase
15+
--exponentgrouping disabled
16+
--fractiongrouping disabled
17+
--header ignore
18+
--hexgrouping 4,8
19+
--hexliteralcase uppercase
20+
--ifdef indent
21+
--indent 4
22+
--indentcase false
23+
--importgrouping testable-bottom
24+
--linebreaks lf
25+
--octalgrouping 4,8
26+
--operatorfunc spaced
27+
--patternlet hoist
28+
--ranges spaced
29+
--self remove
30+
--semicolons inline
31+
--stripunusedargs always
32+
--trimwhitespace always
33+
--wraparguments preserve
34+
--wrapcollections preserve
35+
36+
# rules
37+
38+
--enable isEmpty

.swiftlint

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
disabled_rules: # rule identifiers to exclude from running
2+
- line_length
3+
- function_body_length
4+
- unused_closure_parameter
5+
- valid_docs
6+
- large_tuple
7+
- identifier_name

.swiftlint.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

Core/Constants.swift

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,55 @@
22
// Constants.swift
33
// SwiftyJSONAccelerator
44
//
5-
// Created by Karthikeya Udupa on 01/06/16.
6-
// Copyright © 2016 Karthikeya Udupa K M. All rights reserved.
5+
// Created by Karthikeya Udupa on 24/07/2019.
6+
// Copyright © 2019 Karthikeya Udupa. All rights reserved.
77
//
88

99
import Foundation
1010

11-
/**
12-
Various supported variable types
13-
14-
- String: String.
15-
- Int: Integer.
16-
- Float: Float.
17-
- Double: Double.
18-
- Bool: Boolean.
19-
- Array: Array.
20-
- Object: Object.
21-
*/
11+
/// Various supported variable types
2212
enum VariableType: String {
23-
case string = "String"
24-
case int = "Int"
25-
case float = "Float"
26-
case double = "Double"
27-
case bool = "Bool"
28-
case array = "[]"
29-
case object = "{OBJ}"
30-
case null = "Any"
13+
case string = "String"
14+
case int = "Int"
15+
case float = "Float"
16+
case double = "Double"
17+
case bool = "Bool"
18+
case array = "[]"
19+
case object = "{OBJ}"
20+
case null = "Any"
3121
}
3222

33-
/**
34-
Various types of construct that can be generated.
35-
36-
- classType: Model with construct type class.
37-
- structType: Model with construct type struct.
38-
*/
23+
/// Various types of construct that can be generated.
24+
///
25+
/// - classType: Model with construct type class.
26+
/// - structType: Model with construct type struct.
3927
enum ConstructType: String {
40-
case classType = "class"
41-
case structType = "struct"
28+
case classType = "class"
29+
case structType = "struct"
4230
}
4331

44-
/**
45-
List of supported mapping libraries.
46-
47-
- SwiftyJSON: SwiftyJSON - https://github.com/SwiftyJSON/SwiftyJSON
48-
- ObjectMapper: ObjectMapper - https://github.com/Hearst-DD/ObjectMapper
49-
- Marshal: Marshal - https://github.com/utahiosmac/Marshal
50-
*/
51-
enum JSONMappingLibrary: String {
52-
case libSwiftyJSON = "SwiftyJSON"
53-
case libObjectMapper = "ObjectMapper"
54-
case libMarshal = "Marshal"
32+
/// JSON mapping options available in the UI
33+
///
34+
/// - Swift: Pure Swift 5 Codeable
35+
/// - SwiftCodeExtended: Codeextended along with Swift 5 - https://github.com/JohnSundell/Codextended
36+
enum JSONMappingMethod: String {
37+
case Swift = "SwiftCodingVanilla"
38+
case SwiftCodeExtended
5539
}
5640

57-
/**
58-
Types of property.
59-
60-
- Value: Value type like String, Integer, Float etc.
61-
- ValueArray: Array of Value
62-
- Object: Object type
63-
- ObjectArray: Array of object
64-
- emptyArray: An empty array
65-
- Null: Null value
66-
*/
41+
/// Types of property.
42+
///
43+
/// - Value: Value type like String, Integer, Float etc.
44+
/// - ValueArray: Array of Value
45+
/// - Object: Object type
46+
/// - ObjectArray: Array of object
47+
/// - emptyArray: An empty array
48+
/// - Null: Null value
6749
enum PropertyType: String {
68-
case valueType
69-
case valueTypeArray
70-
case objectType
71-
case objectTypeArray
72-
case emptyArray
73-
case nullType
50+
case valueType
51+
case valueTypeArray
52+
case objectType
53+
case objectTypeArray
54+
case emptyArray
55+
case nullType
7456
}
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,18 @@
99
import Foundation
1010

1111
struct FileGenerator {
12-
13-
/**
14-
Fetch the template for creating model.swift files.
15-
16-
- parameter filename: Name of the file to be loaded
17-
18-
- returns: String containing the template.
19-
*/
12+
/// Fetch the template for creating model.swift files.
13+
///
14+
/// - Parameter filename: Name of the file to be loaded
15+
/// - Returns: String containing the template.
2016
static func loadFileWith(_ filename: String) -> String {
21-
2217
let bundle = Bundle.main
2318
let path = bundle.path(forResource: filename, ofType: "txt")
2419

2520
do {
26-
let content = try String.init(contentsOfFile: path!)
21+
let content = try String(contentsOfFile: path!)
2722
return content
28-
} catch { }
23+
} catch {}
2924

3025
return ""
3126
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// FileGenerator.swift
3+
// SwiftyJSONAccelerator
4+
//
5+
// Created by Karthik on 27/12/2016.
6+
// Copyright © 2016 Karthikeya Udupa K M. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
extension FileGenerator {
12+
static func generateFileContentWith(_ modelFile: ModelFile, configuration: ModelGenerationConfiguration) -> String {
13+
var content = loadFileWith("BaseTemplate")
14+
let singleTab = " ", doubleTab = " "
15+
content = content.replacingOccurrences(of: "{OBJECT_NAME}", with: modelFile.fileName)
16+
content = content.replacingOccurrences(of: "{DATE}", with: todayDateString())
17+
content = content.replacingOccurrences(of: "{OBJECT_KIND}", with: modelFile.type.rawValue)
18+
19+
if let authorName = configuration.authorName {
20+
content = content.replacingOccurrences(of: "__NAME__", with: authorName)
21+
}
22+
if let companyName = configuration.companyName {
23+
content = content.replacingOccurrences(of: "__MyCompanyName__", with: companyName)
24+
}
25+
26+
let stringConstants = modelFile.component.stringConstants.map { doubleTab + $0 }.joined(separator: "\n")
27+
let declarations = modelFile.component.declarations.map { singleTab + $0 }.joined(separator: "\n")
28+
let initialisers = modelFile.component.initialisers.map { doubleTab + $0 }.joined(separator: "\n")
29+
30+
content = content.replacingOccurrences(of: "{STRING_CONSTANT}", with: stringConstants)
31+
content = content.replacingOccurrences(of: "{DECLARATION}", with: declarations)
32+
content = content.replacingOccurrences(of: "{INITIALIZER}", with: initialisers)
33+
34+
return content
35+
}
36+
37+
/**
38+
Write the given content to a file at the mentioned path.
39+
40+
- parameter name: The name of the file.
41+
- parameter content: Content that has to be written on the file.
42+
- parameter path: Path where the file has to be created.
43+
44+
- returns: Boolean indicating if the process was successful.
45+
*/
46+
internal static func writeToFileWith(_ name: String, content: String, path: String) throws {
47+
let filename = path.appendingFormat("%@", name + ".swift")
48+
try FileManager.default.createDirectory(at: URL(fileURLWithPath: path),
49+
withIntermediateDirectories: true,
50+
attributes: nil)
51+
try content.write(toFile: filename, atomically: true, encoding: String.Encoding.utf8)
52+
}
53+
54+
fileprivate static func todayDateString() -> String {
55+
let formatter = DateFormatter()
56+
formatter.dateStyle = .short
57+
return formatter.string(from: Date())
58+
}
59+
}

0 commit comments

Comments
 (0)