I am a swift newbie so please bear with me. I have successfully integrated FirebaseUI into my app. I now wish to localize the strings for Dutch. My whole project is in Dutch so I do not have any localization in the project since it is all hard coded in the storyboard. The FirebaseUI docs say that you should:
// Swift
authUI?.customStringsBundle = NSBundle.mainBundle() // Or any custom bundle.
But I am not sure where to actually place the strings file in the project (or how) or if I should be using a custom bundle?
I have spent a whole day playing around with bundles but without success. Your help would be appreciated!
Here is how I got it to work eventually:
Add a strings file called FirebaseAuthUI.strings. I copied the content of this file from here
Use the following code when you create the controller to handle sign in:
Code:
if let bundlePath = Bundle.main.path(forResource: "FirebaseAuthUI", ofType: "strings") {
let bundle = Bundle(path: bundlePath)
authUI?.customStringsBundle = bundle;
}
Don't forget to translate the strings in step 1.
Good luck
Related
I'm supposed to test PSPDFKit in a way that lets the user open a locally saved pdf file.
For this i require the files url(e.g. path, i guess). How can i let the user pick a local document?
Can anybody help me out?
I'm using storyboard and swift.
You can present a PDF document in PSPDFKit using the PDFViewController like so:
// Create the `Document`.
let fileURL = Bundle.main.url(forResource: "Document", withExtension: "pdf")!
let document = Document(url: fileURL)
// Create the PDF view controller.
let pdfController = PDFViewController(document: document)
// Present the PDF view controller within a `UINavigationController` to enable the toolbar.
present(UINavigationController(rootViewController: pdfController), animated: true)
For more details, take a look at the following guide here.
Also, to present a document that your end-user has selected, consider using a document picker or a file browser. Please refer to DocumentPickerSidebarExample.swift from Catalog and SwiftUI Document Browser for runnable example projects.
In the future, please reach out to our support portal at pspdfkit.com/support/request/ - we're happy to provide support there for our commercial SDK.
I want to start using modular code with the new Swift Package Manager integration with Xcode 11.
The problem is that I can't seem to add any kind of UI files to my new package. I just need to add a xib file.
How is this accomplished?
Currently Swift packages only support source code so you can't add a xib file to the package. Read the What's Missing? section in the following article:
Creating Swift Packages in Xcode
UPDATE
Xcode 12 allows you to add files that are not source code files to Swift packages. I have not created a Swift package so I cannot provide detailed instructions on how to add a xib file to a Swift package. But as #ffritz mentioned in a comment to this answer, Apple's documentation has an article on bundling resources in Swift packages.
Bundling Resources with a Swift Package
Thanks to Marks answer above and the Apple docs he shared, I was able to solve my problem with loading .xib files in my Swift Package. I will explain my steps here for future onlookers.
Move all of my .xib files in my new Swift package into a folder named Resources (in location /Sources/PackageName/Resources)
Change any code I have which loads these .xib files programatically to include the module bundle. E.g:
super.init(nibName: "MyViewController", bundle: nil) //Old way of initialising
super.init(nibName: "MyViewController", bundle: Bundle.module) //New way of initialising
When you create a Swift package with resources Bundle gains automatic static identifiers per package e.g a package called Moon would be accessed via Bundle.moon
e.g to instantiate a cell with a XIB called Crater.xib in Moon you would use
let nib = UINib(nibName: "Crater", bundle: Bundle.moon)
I am working on the new version of swift 4 and i have the next issue, i can not show a ".pdf" on a UIWebView. First i migrated my project to the new version of Swift, then i had to solve the issue of "Set Swift 3 #objc inference to Default", then when i run my project just some of the PDFs i set when i was working on Swift 3 are showing, i added new ones after upgrade the swift but does not show it on the UIWebView. This is my code to show the pdf files:
func showCarPdf() {
print(carPdfView!)
if let pdf = Bundle.main.url(forResource: carPdfView!, withExtension: "pdf", subdirectory: nil, localization: nil) {
let req = NSURLRequest(url: pdf)
webView.loadRequest(req as URLRequest)
}
}
Does any one know whats happend? Why i can only show the files that i set on swift 3 and not the new ones added with the new version. Thanks a lot guys.
From your question I understand that you are adding new pdf file... right?
If so...
By default when a resource(images, pdfs, etc...) is added in Xcode 9, it is not getting added to Target.
If you add a new resource make sure, it is set to Target as well. Hope you know how to check whether a resource is added to Target. You can also verify whether a resource is added from the 'Copy Bundle Resources"
I am loading a html file to WKWebview from local everything is working fine but it is not showing image on iPhone.
This is the code i am using to load a html file
do{
let fileName = try String(contentsOf: destinationURLForFile)
print("fileName is equal to\(fileName)")
webView.loadHTMLString(fileName, baseURL: destinationURLForFile)
}catch{
}
Trying to fix since hours. Any suggestions would be helpful!
I had a very similar issue yesterday, you need to tell the build to copy this file to the device as part of the bundle.
Make sure sure you have the HTML file in the Copy Bundle Resources part of the build settings. Just go to the project settings > build phases > copy bundle resources and if your HTML file is not listed there, click the + button and add it.
This should solve your issue, if not could you please provide more information, are you getting any errors, does the file actually exist?
I want to add my own Markdown file, a file named profile.md. However, I don't know where I should add the file in my Vapor project, which is developed in Xcode.
I tried adding it to Sources/ or just the root directory, but it cannot be searched by Bundle.main.url(forResource:) function, like:
guard let url = Bundle.main.url(forResource: "profile", withExtension: ".md") else { ... }
Also, I found that I already added it under Copy Bundle Resources tab.
In the normal app (for iOS and macOS), the function above works properly.
How can I add my own file to be used in Vapor project developed in Xcode?
This is a very basic example of loading the contents of a file from a custom location using Foundation rather than Vapor's template view loading mechanism, and returning it as a text response.
drop.get { req in
let templateString = try String(contentsOfFile: drop.workDir + "Resources/profile.md")
return templateString
}
I'm not sure exactly what you mean by "parse, and embed it into another template file" but you'd put that bit in between the lines above.