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-3328] Cannot extend PHFetchResult to conform to Sequence in Swift 3 #45916
Comments
Anticipated by https://bugs.swift.org/browse/SR-1576 |
A not-so-pretty workaround: use a wrapper type.
|
@belkadan thanks! |
Yes, this is the same problem as SR-1576. Conforming with |
@jckarter Does it depend on https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md being implemented? If so, not usable currently. |
No, just unconditionally use `typealias Element = AnyObject` and force-cast to PHFetchResult<AnyObject>. |
@jckarter I'm lost. Where to put `typealias Element = AnyObject`? `Sequence` doesn't have the associated type `Element`. |
I meant something like this: import Photos
extension PHFetchResult: Sequence {
public func makeIterator() -> FetchResultIterator {
return FetchResultIterator(self as! PHFetchResult<AnyObject>)
}
}
@objc public class FetchResultIterator: NSObject, IteratorProtocol {
// iterator implementation here
} Extensions of ObjC generic classes are limited to being |
@jckarter Thanks! It's a better workaround because only the extension implementation needs patches. |
Comment by Marc Knaup (JIRA) The following code works fine in release mode but crashes at runtime in debug mode in some cases (e.g. when calling extension NSFastEnumeration {
public func makeIterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self)
}
}
extension PHFetchResult: Sequence {} Looks like that no matter how you make |
@swift-ci create |
Additional Detail from JIRA
md5: cf208174c2cc5e5b041dd6cefebc53cb
relates to:
Issue Description:
This used to work in Swift 2 but now in Swift 3 reports this error:
Extension of a generic Objective-C class cannot access the class's generic parameters at runtime.
I know it is due to current limitation of the language but is there any temporary workaround?
The text was updated successfully, but these errors were encountered: