Skip to content
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

App crashing due to path = nil #43

Open
famictech2000 opened this issue Jan 13, 2018 · 1 comment
Open

App crashing due to path = nil #43

famictech2000 opened this issue Jan 13, 2018 · 1 comment

Comments

@famictech2000
Copy link

let path = Bundle.main.path(forResource: "SAConfettiView", ofType: "bundle")

let bundle = Bundle(path: path!)

How do I fix this!?

@benicelabs
Copy link

Replace
let path = Bundle(for: SAConfettiView.self).path(forResource: "SAConfettiView", ofType: "bundle") let bundle = Bundle(path: path!) let imagePath = bundle?.path(forResource: fileName, ofType: "png") let url = URL(fileURLWithPath: imagePath!) do { let data = try Data(contentsOf: url) return UIImage(data: data) } catch { print(error) }

with this
if let image = UIImage(named: fileName) { return image } else { return nil }

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

No branches or pull requests

2 participants