File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1644,3 +1644,23 @@ extension NSString : _StructTypeBridgeable {
1644
1644
return _StructType. _unconditionallyBridgeFromObjectiveC ( self )
1645
1645
}
1646
1646
}
1647
+
1648
+ extension NSString : CVarArg {
1649
+ @inlinable // c-abi
1650
+ public var _cVarArgEncoding : [ Int ] {
1651
+ return _encodeBitsAsWords ( unsafeBitCast ( self , to: CFString . self) )
1652
+ }
1653
+ }
1654
+
1655
+ extension String : CVarArg {
1656
+ @inlinable // c-abi
1657
+ public var _cVarArgEncoding : [ Int ] {
1658
+ // We don't have an autorelease pool to retain the NSString until the withVaList closure is complete.
1659
+ // So add an operation to release on the next cycle of this thread.
1660
+ let ns = Unmanaged . passRetained ( NSString ( string: self ) )
1661
+ OperationQueue . current? . addOperation {
1662
+ ns. release ( )
1663
+ }
1664
+ return ns. takeUnretainedValue ( ) . _cVarArgEncoding
1665
+ }
1666
+ }
Original file line number Diff line number Diff line change @@ -813,6 +813,15 @@ class TestNSString: LoopbackServerTest {
813
813
}
814
814
}
815
815
816
+ func test_initializeWithFormat4( ) {
817
+ let argument : [ CVarArg ] = [ " One " , " Two " , " Three " ]
818
+ withVaList ( argument) {
819
+ pointer in
820
+ let string = NSString ( format: " Testing %@ %@ %@ " , arguments: pointer)
821
+ XCTAssertEqual ( string, " Testing One Two Three " )
822
+ }
823
+ }
824
+
816
825
func test_appendingPathComponent( ) {
817
826
do {
818
827
let path : NSString = " /tmp "
@@ -1677,6 +1686,7 @@ class TestNSString: LoopbackServerTest {
1677
1686
( " test_initializeWithFormat " , test_initializeWithFormat) ,
1678
1687
( " test_initializeWithFormat2 " , test_initializeWithFormat2) ,
1679
1688
( " test_initializeWithFormat3 " , test_initializeWithFormat3) ,
1689
+ ( " test_initializeWithFormat4 " , test_initializeWithFormat4) ,
1680
1690
( " test_appendingPathComponent " , test_appendingPathComponent) ,
1681
1691
( " test_deletingLastPathComponent " , test_deletingLastPathComponent) ,
1682
1692
( " test_getCString_simple " , test_getCString_simple) ,
You can’t perform that action at this time.
0 commit comments