Skip to content

NSMutableArray replaceObjectsInRange:withObjectsFromArray:range: #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 16, 2015

Conversation

joshuatbrown
Copy link
Contributor

Tested and implemented NSMutableArray's replaceObjectsInRange:withObjectsFromArray:range:

@@ -658,7 +658,10 @@ public class NSMutableArray : NSArray {
}
}
}
public func replaceObjectsInRange(range: NSRange, withObjectsFromArray otherArray: [AnyObject], range otherRange: NSRange) { NSUnimplemented() }
public func replaceObjectsInRange(range: NSRange, withObjectsFromArray otherArray: [AnyObject], range otherRange: NSRange) {
replaceObjectsInRange(range, withObjectsFromArray: otherArray.bridge().subarrayWithRange(otherRange))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bridge here is not needed since otherArray is already an Array<AnyObject>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm on it.

@joshuatbrown
Copy link
Contributor Author

@phausler OK, I switched it to convert the NSRange to a Range<Int> instead of bridging the array. Let me know if I should make any more changes. Thanks!

@joshuatbrown
Copy link
Contributor Author

@phausler I just saw your comment on #139 (which is another implementation of the same method) saying it should work like this:

var list = [AnyObject]()
array.getObjects(&list, range:otherRange)
replaceObjectsInRange(range, withObjectsFromArray:list)

Should I update the implementation in this PR to follow that pattern?

@phausler
Copy link
Contributor

Personally I think that is the most reasonable pattern: I will likely try to merge all of the unit tests together from the desperate requests for this implementation

@joshuatbrown
Copy link
Contributor Author

Hmm... Just looked at it and noticed that it only works if we bridge otherArray to a NSArray since getObjects is defined on NSArray. Here's the (tested, passing) code, which I'm happy to add to the PR if calling bridge() is acceptable:

var list = [AnyObject]()
otherArray.bridge().getObjects(&list, range:otherRange)
replaceObjectsInRange(range, withObjectsFromArray:list)

@phausler
Copy link
Contributor

yea bridge is fine here, usually we have tried to use ._swiftObject internally to Foundation bridge is just a simple wrapper around that.

@joshuatbrown
Copy link
Contributor Author

Ready for review again.

@phausler
Copy link
Contributor

looks good to me

phausler added a commit that referenced this pull request Dec 16, 2015
NSMutableArray replaceObjectsInRange:withObjectsFromArray:range:
@phausler phausler merged commit 15a0579 into swiftlang:master Dec 16, 2015
@joshuatbrown joshuatbrown deleted the replaceObjectsInRange branch December 16, 2015 19:34
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
Add infrastructure for test projects using IndexStoreDB's "Tibs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants