Mohan Meruva
Mohan Meruva

Reputation: 322

Unable to access Bundle in swift file

I am trying to get some info from a plist but when I try to access bundle in a swift file I am not able to access it. When I type bundle, Xcode is not recommending anything. It works on other swift files in the same project. I don't know what can be the issue.

Upvotes: 0

Views: 458

Answers (2)

Thanh Vu
Thanh Vu

Reputation: 1739

It's may a bug of Xcode about code suggestion. You can access Bundle.main normally without any problem.

Restart Xcode may solve code suggestion problem.

UPDATE: If your file not import Foundation or UIKit, You must import Foundation to access Bundle

Upvotes: 0

Chris Zielinski
Chris Zielinski

Reputation: 1391

Since Bundle is a Foundation class, ensure you are importing the Foundation framework at the beginning of your Swift file.

đź“Ś Note: UIKit includes the Foundation framework, so you can alternatively import UIKit.

import Foundation

This should enable SourceKit’s—& therefore Xcode’s—code completion.

Upvotes: 2

Related Questions