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
[SR-1576] Swift 3 can't subscript PHFetchResult #44185
Comments
@mattneub Thanks for following up! I encountered a similar problem locally while testing (tracked internally as rdar://problem/26602097), where associated types that refer to the ObjC class's generic parameters would cause a crash. If you can make it adopt `Sequence` with `AnyObject` as its element type, that might work around the problem, even though it's of course not ideal. |
@jckarter Unfortunately this is not as fixed as I thought; in one project, I can subscript PHFetchResult, but in another, I can't. |
@mattneub Are you building both with the same toolchain? Is there any difference in how PHFetchResult is used—maybe one uses it in a generic context, while the other binds it to a specific parameter type? |
@jckarter It's weird. If I say let asset = self.photos[ix]
dvc.asset = asset everything is fine. If I try to condense that into one line dvc.asset = self.photos[ix] the compiler crashes. |
@jckarter Okay, I see what the difference is. `dvc.asset` is an Optional. I can work around this by saying |
Definitely not. Thanks for narrowing it down. |
@jckarter Here's a test case. This crashes the compiler on my machine: import UIKit
import Photos
class DataViewController : UIViewController {
var asset : PHAsset!
}
class ModelController: NSObject {
var photos : PHFetchResult<PHAsset>!
func test(ix:Int) {
let d = DataViewController()
d.asset = self.photos[0] // workaround is: d.asset = Optional(self.photos[0])
}
} |
Great test case. Is it OK for me to use that as a release note until we fix the bug? |
@jckarter Of course - no need to ask. I'm just happy that I found a workaround. 🙂 |
Trying a fix: #4128 |
@jckarter I still can't find a way to make PHFetchResult respond to `for...in`, even though it adopts NSFastEnumeration in Objective-C. Should I be posting that as a separate bug? |
@mattneub It would need to conform to |
@jckarter Understood, but the fact that `for...in` can be used in Objective-C but not in Swift is kind of dreadful. I used to be able to work around this by making PHFetchResult conform to SequenceType (as it was called in those days), but now I don't know how to do that, because of the generic. And even in the old days, I shouldn't have had to work around it myself, I feel. Nothing is more natural than to want to cycle thru your fetch results, and the `enumerate` methods are unSwifty. |
@jckarter you mentioned "it may have to use AnyObject as its element type to do so". But how exactly? Can you show me the code? Thanks. |
Environment
Toolchain: Swift Development Snapshot 2016-05-09 (a)
Additional Detail from JIRA
md5: b0225e3be4ccb6e322b1c4940f69ccb9
relates to:
Issue Description:
This crashes the compiler (Command failed due to signal: Illegal instruction: 4):
The problem is the attempt to subscript
result
. A workaround is:But this should not be necessary.
This may be related to SR-1522.
Another possibly related issue is that I was previously working around the fact that you can't use
for...in
with PHFetchResult by making it adopt SequenceType. The Swift 3 equivalent of my code would be:But that, too, crashes the compiler.
The text was updated successfully, but these errors were encountered: