diff --git a/__tests__/formats/__snapshots__/swiftFile.test.js.snap b/__tests__/formats/__snapshots__/swiftFile.test.js.snap index acee8fe60..0ef31d254 100644 --- a/__tests__/formats/__snapshots__/swiftFile.test.js.snap +++ b/__tests__/formats/__snapshots__/swiftFile.test.js.snap @@ -72,3 +72,39 @@ public struct StyleDictionary { } " `; + +exports[`formats ios-swift/any.swift with static should match snapshot 1`] = ` +" +// +// __output/ +// + +// Do not edit directly +// Generated on Sat, 01 Jan 2000 00:00:00 GMT + + +import UIKit + +public class StyleDictionary { + public static let colorBaseRed = UIColor(red: 1.000, green: 0.000, blue: 0.000, alpha: 1) +} +" +`; + +exports[`formats ios-swift/any.swift without static should match snapshot 1`] = ` +" +// +// __output/ +// + +// Do not edit directly +// Generated on Sat, 01 Jan 2000 00:00:00 GMT + + +import UIKit + +public class StyleDictionary { + public let colorBaseRed = UIColor(red: 1.000, green: 0.000, blue: 0.000, alpha: 1) +} +" +`; diff --git a/__tests__/formats/swiftFile.test.js b/__tests__/formats/swiftFile.test.js index 9eefeb4d6..5c6a2d648 100644 --- a/__tests__/formats/swiftFile.test.js +++ b/__tests__/formats/swiftFile.test.js @@ -89,6 +89,24 @@ describe('formats', () => { }), {}, file)).toMatchSnapshot(); }); + it('without static should match snapshot', () => { + file.options.static = false + expect(format(createFormatArgs({ + dictionary, + file, + platform: {} + }), {}, file)).toMatchSnapshot(); + }); + + it('with static should match snapshot', () => { + file.options.static = true + expect(format(createFormatArgs({ + dictionary, + file, + platform: {} + }), {}, file)).toMatchSnapshot(); + }); + }); }); \ No newline at end of file diff --git a/docs/formats.md b/docs/formats.md index 5d922ce78..f1aa807a4 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -1563,7 +1563,10 @@ Creates a Swift implementation file of a class with values. It adds default `cla optionsObject - [options.accessControl]Stringpublic

Level of access of the generated swift object

+ [options.accessControl]Stringpublic

Level of access of the generated swift object

+ + + [options.static]Booleantrue

Type of property of the generated swift object

[options.import]Array.<String>UIKit

Modules to import. Can be a string or array of strings

@@ -1605,6 +1608,9 @@ Creates a Swift implementation file of an enum with values. It adds default `enu optionsObject [options.accessControl]Stringpublic

Level of access of the generated swift object

+ + + [options.static]Booleantrue

Type of property of the generated swift object

[options.import]Array.<String>UIKit

Modules to import. Can be a string or array of strings

@@ -1650,6 +1656,9 @@ accessControl: 'internal', optionsObject [options.accessControl]Stringpublic

Level of access of the generated swift object

+ + + [options.static]Booleantrue

Type of property of the generated swift object

[options.import]Array.<String>UIKit

Modules to import. Can be a string or array of strings

diff --git a/lib/common/formatHelpers/setSwiftFileProperties.js b/lib/common/formatHelpers/setSwiftFileProperties.js index 15341401f..ac7dcb3c8 100644 --- a/lib/common/formatHelpers/setSwiftFileProperties.js +++ b/lib/common/formatHelpers/setSwiftFileProperties.js @@ -49,6 +49,10 @@ function setSwiftFileProperties(options, objectType, transformGroup) { } } + if (typeof options.static === 'undefined') { + options.static = true; + } + return options } diff --git a/lib/common/formats.js b/lib/common/formats.js index 685967389..ca183ce69 100644 --- a/lib/common/formats.js +++ b/lib/common/formats.js @@ -926,7 +926,8 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul * @memberof Formats * @kind member * @param {Object} options - * @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) of the generated swift object + * @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/accesscontrol/) of the generated swift object + * @param {Boolean} [options.static=true] - Type of property of the generated swift object * @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of strings * @param {String} [options.className] - The name of the generated Swift class * @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date @@ -969,6 +970,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul * @kind member * @param {Object} options * @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) of the generated swift object + * @param {Boolean} [options.static=true] - Type of property of the generated swift object * @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of strings * @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date * @param {Boolean} [options.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output. @@ -1016,6 +1018,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul * @kind member * @param {Object} options * @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) of the generated swift object + * @param {Boolean} [options.static=true] - Type of property of the generated swift object * @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of strings * @param {String} [options.objectType=class] - The type of the generated Swift object * @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date diff --git a/lib/common/templates/ios-swift/any.swift.template b/lib/common/templates/ios-swift/any.swift.template index dd6cb367a..ec6ec6a2f 100644 --- a/lib/common/templates/ios-swift/any.swift.template +++ b/lib/common/templates/ios-swift/any.swift.template @@ -24,6 +24,6 @@ <%= options.accessControl %><%= options.objectType %> <%= file.className %> { <%= allTokens.map(function(prop) { - return options.accessControl + 'static let ' + formatProperty(prop); + return options.accessControl + (options.static ? 'static ' : '') + 'let ' + formatProperty(prop); }).join('\n ') %> }