Skip to content

Commit 5902a47

Browse files
committed
Print IB_DESIGNABLE and IBInspectable in the generated ObjC header
Add support for @IBDesignable and @IBInspectable attribute to the generated ObjC headers
1 parent f8209f2 commit 5902a47

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ class DeclAndTypePrinter::Implementation
278278
if (CD->getAttrs().hasAttribute<WeakLinkedAttr>())
279279
os << "SWIFT_WEAK_IMPORT\n";
280280

281+
if (CD->getAttrs().hasAttribute<IBDesignableAttr>()) {
282+
os << "IB_DESIGNABLE\n";
283+
}
284+
281285
bool hasResilientAncestry =
282286
CD->checkAncestry().contains(AncestryFlags::ResilientOther);
283287
if (hasResilientAncestry) {
@@ -1189,6 +1193,10 @@ class DeclAndTypePrinter::Implementation
11891193
}
11901194

11911195
os << ") ";
1196+
if (VD->getAttrs().hasAttribute<IBInspectableAttr>()) {
1197+
os << "IBInspectable ";
1198+
}
1199+
11921200
if (VD->getAttrs().hasAttribute<IBOutletAttr>()) {
11931201
if (!maybePrintIBOutletCollection(ty))
11941202
os << "IBOutlet ";

test/PrintAsObjC/classes.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,14 @@ typealias AliasForNSRect = NSRect
359359
@objc func testBridgingOptionality(_ a: UnsafePointer<Int>?, b: UnsafeMutablePointer<Int>!, c: AutoreleasingUnsafeMutablePointer<Methods?>?) {}
360360
}
361361

362+
// CHECK-LABEL: IB_DESIGNABLE
363+
// CHECK-NEXT: SWIFT_CLASS(
364+
// CHECK-NEXT: @interface MyDesignableObject : NSObject
365+
// CHECK-NEXT: init
366+
// CHECK-NEXT: @end
367+
// NEGATIVE-NOT: @interface NSObject
368+
@IBDesignable class MyDesignableObject : NSObject {}
369+
362370
// CHECK-LABEL: @interface MyObject : NSObject
363371
// CHECK-NEXT: init
364372
// CHECK-NEXT: @end
@@ -517,6 +525,7 @@ public class NonObjCClass { }
517525
// CHECK-NEXT: @property (nonatomic) CFAliasForTypeRef _Nullable anyCF2;
518526
// CHECK-NEXT: @property (nonatomic, weak) IBOutlet id _Null_unspecified outlet;
519527
// CHECK-NEXT: @property (nonatomic, strong) IBOutlet Properties * _Null_unspecified typedOutlet;
528+
// CHECK-NEXT: @property (nonatomic) IBInspectable NSInteger inspectable;
520529
// CHECK-NEXT: @property (nonatomic, copy) NSString * _Nonnull string;
521530
// CHECK-NEXT: @property (nonatomic, copy) NSArray * _Nonnull array;
522531
// CHECK-NEXT: @property (nonatomic, copy) NSArray<NSArray<NSNumber *> *> * _Nonnull arrayOfArrays;
@@ -608,6 +617,7 @@ public class NonObjCClass { }
608617

609618
@IBOutlet weak var outlet: AnyObject!
610619
@IBOutlet var typedOutlet: Properties!
620+
@IBInspectable var inspectable: Int = 0
611621

612622
@objc var string = "abc"
613623
@objc var array: Array<AnyObject> = []

0 commit comments

Comments
 (0)