diff --git a/src/swift/CHANGELOG.md b/src/swift/CHANGELOG.md index 119353cd520..0f3d3ed4f66 100644 --- a/src/swift/CHANGELOG.md +++ b/src/swift/CHANGELOG.md @@ -1,5 +1,10 @@ # Release History +## Version 0.1.3 (Unreleased) +- Support for getter/setter blocks. +- Fixed issue where read-only properties would appear as + read/write due to not displaying `{ get }` syntax. + ## Version 0.1.2 (Unreleased) - Fixed issue where empty extension blocks were displayed. - Temporarily will allow duplicate IDs. This will result in diff --git a/src/swift/SwiftAPIView/SwiftAPIView.xcodeproj/project.pbxproj b/src/swift/SwiftAPIView/SwiftAPIView.xcodeproj/project.pbxproj index ed892fe3202..b09784712fc 100644 --- a/src/swift/SwiftAPIView/SwiftAPIView.xcodeproj/project.pbxproj +++ b/src/swift/SwiftAPIView/SwiftAPIView.xcodeproj/project.pbxproj @@ -295,7 +295,7 @@ ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 1.0.0; + MARKETING_VERSION = 0.1.3; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SwiftAPIView; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -311,7 +311,7 @@ ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 1.0.0; + MARKETING_VERSION = 0.1.3; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SwiftAPIView; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/src/swift/SwiftAPIViewCore/Sources/Models/Declarations/VariableModel.swift b/src/swift/SwiftAPIViewCore/Sources/Models/Declarations/VariableModel.swift index 4776b06f83b..09a6aa9b6ab 100644 --- a/src/swift/SwiftAPIViewCore/Sources/Models/Declarations/VariableModel.swift +++ b/src/swift/SwiftAPIViewCore/Sources/Models/Declarations/VariableModel.swift @@ -69,11 +69,11 @@ class VariableModel: Tokenizable, Commentable, AccessLevelProtocol { case let .initializerList(initializerList): initializers = initializerList.compactMap { InitializerItemModel(from: $0) } case let .codeBlock(ident, typeAnno, _): - initializers = [InitializerItemModel(name: ident.textDescription, typeModel: TypeAnnotationModel(from: typeAnno), defaultValue: nil)] + initializers = [InitializerItemModel(name: ident.textDescription, typeModel: TypeAnnotationModel(from: typeAnno), defaultValue: nil, hasGetter: true)] case let .getterSetterKeywordBlock(ident, typeAnno, _): - initializers = [InitializerItemModel(name: ident.textDescription, typeModel: TypeAnnotationModel(from: typeAnno), defaultValue: nil)] + initializers = [InitializerItemModel(name: ident.textDescription, typeModel: TypeAnnotationModel(from: typeAnno), defaultValue: nil, hasGetter: true, hasSetter: true)] case let .getterSetterBlock(ident, typeAnno, _): - initializers = [InitializerItemModel(name: ident.textDescription, typeModel: TypeAnnotationModel(from: typeAnno), defaultValue: nil)] + initializers = [InitializerItemModel(name: ident.textDescription, typeModel: TypeAnnotationModel(from: typeAnno), defaultValue: nil, hasGetter: true, hasSetter: true)] case let .willSetDidSetBlock(ident, typeAnno, expression, _): // the willSetDidSet block is irrelevant from an API perspective // so we ignore it. diff --git a/src/swift/SwiftAPIViewCore/Sources/Models/Miscellaneous/InitializerItemModel.swift b/src/swift/SwiftAPIViewCore/Sources/Models/Miscellaneous/InitializerItemModel.swift index 0c0b5858fa5..36065306de8 100644 --- a/src/swift/SwiftAPIViewCore/Sources/Models/Miscellaneous/InitializerItemModel.swift +++ b/src/swift/SwiftAPIViewCore/Sources/Models/Miscellaneous/InitializerItemModel.swift @@ -32,17 +32,23 @@ struct InitializerItemModel: Tokenizable { let name: String let typeModel: TypeAnnotationModel? let defaultValue: String? + let hasGetter: Bool + let hasSetter: Bool init(from source: PatternInitializer) { name = source.name! typeModel = TypeAnnotationModel(from: source.typeModel) defaultValue = source.defaultValue + hasGetter = false + hasSetter = false } - init(name: String, typeModel: TypeAnnotationModel?, defaultValue: String?) { + init(name: String, typeModel: TypeAnnotationModel?, defaultValue: String?, hasGetter: Bool = false, hasSetter: Bool = false) { self.name = name self.typeModel = typeModel self.defaultValue = defaultValue + self.hasGetter = hasGetter + self.hasSetter = hasSetter } func tokenize(apiview a: APIViewModel) { @@ -55,5 +61,17 @@ struct InitializerItemModel: Tokenizable { a.punctuation("=", prefixSpace: true, postfixSpace: true) a.literal(defaultValue) } + + if hasGetter && hasSetter { + a.punctuation("{", prefixSpace: true, postfixSpace: true) + a.keyword("get") + a.punctuation(",", postfixSpace: true) + a.keyword("set") + a.punctuation("}", prefixSpace: true, postfixSpace: true) + } else if hasGetter { + a.punctuation("{", prefixSpace: true, postfixSpace: true) + a.keyword("get") + a.punctuation("}", prefixSpace: true, postfixSpace: true) + } } } diff --git a/src/swift/SwiftAPIViewCore/SwiftAPIViewCore.xcodeproj/project.pbxproj b/src/swift/SwiftAPIViewCore/SwiftAPIViewCore.xcodeproj/project.pbxproj index 05b11133440..bb5dc2dfa93 100644 --- a/src/swift/SwiftAPIViewCore/SwiftAPIViewCore.xcodeproj/project.pbxproj +++ b/src/swift/SwiftAPIViewCore/SwiftAPIViewCore.xcodeproj/project.pbxproj @@ -655,7 +655,7 @@ "@executable_path/../Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 0.1.0; + MARKETING_VERSION = 0.1.3; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SwiftAPIViewCore; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -685,7 +685,7 @@ "@executable_path/../Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 0.1.0; + MARKETING_VERSION = 0.1.3; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SwiftAPIViewCore; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; diff --git a/src/swift/SwiftAPIViewTests/Sources/PropertiesTestFile.swift b/src/swift/SwiftAPIViewTests/Sources/PropertiesTestFile.swift index 067f4818ee0..2185c9279e1 100644 --- a/src/swift/SwiftAPIViewTests/Sources/PropertiesTestFile.swift +++ b/src/swift/SwiftAPIViewTests/Sources/PropertiesTestFile.swift @@ -28,7 +28,7 @@ import Foundation public class PropertiesTestStruct { - var totalSteps: Int = 0 { + public var totalSteps: Int = 0 { willSet(newTotalSteps) { print("About to set totalSteps to \(newTotalSteps)") @@ -40,5 +40,19 @@ public class PropertiesTestStruct { } } } + + public var someReadOnly: String { + return "test" + } + + public var someReadWrite: String { + get { + return "test" + } + + set { + self = newValue + } + } } diff --git a/src/swift/SwiftAPIViewTests/SwiftAPIViewTests.xcodeproj/project.pbxproj b/src/swift/SwiftAPIViewTests/SwiftAPIViewTests.xcodeproj/project.pbxproj index 08465a05f72..6dad8fe140e 100644 --- a/src/swift/SwiftAPIViewTests/SwiftAPIViewTests.xcodeproj/project.pbxproj +++ b/src/swift/SwiftAPIViewTests/SwiftAPIViewTests.xcodeproj/project.pbxproj @@ -373,7 +373,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.0; + MARKETING_VERSION = 0.1.3; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SwiftAPIViewTests; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -403,7 +403,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.0; + MARKETING_VERSION = 0.1.3; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SwiftAPIViewTests; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES;