Where should I add my own Markdown file in Vapor project? - swift

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.

Related

Swift how to reference an image file that is not in *.xcassets folder in storyboard

I was trying to update the icon of my app in LaunchScreen, turned out that the UIImage doesn't update for the situation that a user update from old version to new version, and I searched on web for some solutions, there is one suggesting that I should load image files that are out of the *.xcassets folder, I know how to put the image files to my project root directory, but I don't know how to load it in storyboard, as LaunchScreen.storyboard can't have a view controller class
So my question is: How to reference image files in storyboard
This is the source link: http://arsenkin.com/launch_screen_image_cache.html
You can't use any custom behavior in LaunchScreen.storyboard. And loading images from anywhere except *.xcassets is a custom behavior.
Generally you'd use something like
let path = Bundle.main.path(forResource: "image", ofType: "imageType")
let image = UIImage(contentsOfFile: path!)
to load such an image, but as I've already mentioned, this approach doesn't work for launch screens

how can i let a user pick a local document?

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.

swift 4 - Can not show pdf in a UIWebView

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"

Swift : WKWebView not showing image on device

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?

Localizing FirebaseUI Auth

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