Skip to content

Commit 257172d

Browse files
committed
[NSString] Add implementation of intValue and tests
1 parent 6681af4 commit 257172d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Foundation/NSString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ extension NSString {
457457

458458
public var intValue: Int32 {
459459
get {
460-
NSUnimplemented()
460+
return NSScanner(string: _swiftObject).scanInt() ?? 0
461461
}
462462
}
463463

TestFoundation/TestNSString.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class TestNSString : XCTestCase {
2424
("test_boolValue", test_boolValue ),
2525
("test_BridgeConstruction", test_BridgeConstruction ),
2626
("test_integerValue", test_integerValue ),
27+
("test_intValue", test_intValue ),
2728
("test_isEqualToStringWithSwiftString", test_isEqualToStringWithSwiftString ),
2829
("test_isEqualToObjectWithNSString", test_isEqualToObjectWithNSString ),
2930
("test_isNotEqualToObjectWithNSNumber", test_isNotEqualToObjectWithNSNumber ),
@@ -95,6 +96,14 @@ class TestNSString : XCTestCase {
9596
XCTAssertEqual(string8.integerValue, 0)
9697
}
9798

99+
func test_intValue() {
100+
let string1: NSString = "2147483648"
101+
XCTAssertEqual(string1.intValue, 2147483647)
102+
103+
let string2: NSString = "-2147483649"
104+
XCTAssertEqual(string2.intValue, -2147483648)
105+
}
106+
98107
func test_isEqualToStringWithSwiftString() {
99108
let string: NSString = "literal"
100109
let swiftString = "literal"

0 commit comments

Comments
 (0)