Skip to content

Parity: Bundle.classNamed(_:) and Bundle.principalClass. #2073

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 1 commit into from
Apr 9, 2019
Merged

Parity: Bundle.classNamed(_:) and Bundle.principalClass. #2073

merged 1 commit into from
Apr 9, 2019

Conversation

millenomi
Copy link
Contributor

.classNamed(_:) can now be used, though with a limitation noted in the comments. .principalClass is now implemented in terms of .classNamed(_:).

Fixes SR-10362.

.classNamed(_:) can now be used, though with a limitation noted in the comments. .principalClass is now implemented in terms of .classNamed(_:)
@millenomi
Copy link
Contributor Author

@swift-ci please test


open var principalClass: AnyClass? {
// NB: Cross-platform Swift doesn't have a notion of 'the first class in the ObjC segment' that ObjC platforms have. For swift-corelibs-foundation, if a bundle doesn't have a principal class named, the principal class is nil.
guard let name = infoDictionary?["NSPrincipalClass"] as? String else { return nil }
Copy link
Contributor

Choose a reason for hiding this comment

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

If the principal class is not specified in the information dictionary, the bundle identifies the first class loaded as the principal class. When several classes are linked into a dynamically loadable file, the default principal class is the first one listed on the ld command line.

Reading the documentation looks like the principle-class-not-found case is not handle here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is the case the comment notes, and the comment notes why we don't handle it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for confirming.

@millenomi millenomi merged commit da430b5 into swiftlang:master Apr 9, 2019
@millenomi millenomi deleted the bundle-classNamed-principalClass branch April 9, 2019 20:48
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.

2 participants