I was wondering if, in Xcode, it was possible to find and change all references to the name of a header file, and chage it with something else and still have it work, what I mean is find a name like this: , and have it find all references to it like this: , and this: and replace them with the new name. Thank you
You can rename a class with the "Refactor" function in Xcode:
Select the class name "BlueJaysViewController" in "#implementation BlueJaysViewController".
Choose Edit -> Refactor -> Rename ...
Enter the new class name and select "Rename related files"
Related
I need to read a text file with readLines() and I've already found this question, but the code in the answers always uses some variation of javaClass; it seems to work only inside a class, while I'm using just a simple Kotlin file with no declared classes. Writing it like this is correct syntax-wise but it looks really ugly and it always returns null, so it must be wrong:
val lines = object {}.javaClass.getResource("file.txt")?.toURI()?.toPath()?.readLines()
Of course I could just specify the raw path like this, but I wonder if there's a better way:
val lines = File("src/main/resources/file.txt").readLines()
Thanks to this answer for providing the correct way to read the file. Currently, reading files from resources without using javaClass or similar constructs doesn't seem to be possible.
// use this if you're inside a class
val lines = this::class.java.getResourceAsStream("file.txt")?.bufferedReader()?.readLines()
// use this otherwise
val lines = object {}.javaClass.getResourceAsStream("file.txt")?.bufferedReader()?.readLines()
According to other similar questions I've found, the second way might also work within a lambda but I haven't tested it. Notice the need for the ?. operator and the lines?.let {} syntax needed from this point onward, because getResourceAsStream() returns null if no resource is found with the given name.
Kotlin doesn't have its own means of getting a resource, so you have to use Java's method Class.getResource. You should not assume that the resource is a file (i.e. don't use toPath) as it could well be an entry in a jar, and not a file on the file system. To read a resource, it is easier to get the resource as an InputStream and then read lines from it:
val lines = this::class.java.getResourceAsStream("file.txt").bufferedReader().readLines()
I'm not sure if my response attempts to answer your exact question, but perhaps you could do something like this:
I'm guessing in the final use case, the file names would be dynamic - Not statically declared. In which case, if you have access to or know the path to the folder, you could do something like this:
// Create an extension function on the String class to retrieve a list of
// files available within a folder. Though I have not added a check here
// to validate this, a condition can be added to assert if the extension
// called is executed on a folder or not
fun String.getFilesInFolder(): Array<out File>? = with(File(this)) { return listFiles() }
// Call the extension function on the String folder path wherever required
fun retrieveFiles(): Array<out File>? = [PATH TO FOLDER].getFilesInFolder()
Once you have a reference to the List<out File> object, you could do something like this:
// Create an extension function to read
fun File.retrieveContent() = readLines()
// You can can further expand this use case to conditionally return
// readLines() or entire file data using a buffered reader or convert file
// content to a Data class through GSON/whatever.
// You can use Generic Constraints
// Refer this article for possibilities
// https://kotlinlang.org/docs/generics.html#generic-constraints
// Then simply call this extension function after retrieving files in the folder.
listOfFiles?.forEach { singleFile -> println(singleFile.retrieveContent()) }
In order to have the same url that work for both Jar or in local, the url (or path) needs to be a relative path from the repository root.
..meaning, the location of your file or folder from your src folder.
could be "/main/resources/your-folder/" or "/client/notes/somefile.md"
The url must be a relative path from the repository root.
it must be "src/main/resources/your-folder/" or "src/client/notes/somefile.md"
Now you get the drill, and luckily for Intellij Idea users, you can get the correct path with a right-click on the folder or file -> copy Path/Reference.. -> Path From Repository Root (this is it)
Last, paste it and do your thing.
I'm tinkering with blogdown and would like to create figures and table with non-English caption headers. The following chunk
```{r label1, echo=FALSE, fig.cap="Fancy caption", fig.fullwidth=TRUE}
plot(1,1)
```
produces the plot and a caption that reads
Figure 1: Fancy caption
I'd like to be able to change the label such that, say, "Figure" becomes "Plot". I thought I could fix it in the same way as for bookdown: In the _bookdown.yml file I could have
language:
ui:
chapter_name: "Chap "
appendix_name: "App "
label:
fig: 'Plot '
tab: 'Fancy table '
but I'm not sure how to do something similar with a Hugo-based setup from blogdown. How can I add the above information to, say, the config.toml file or set it somewhere else?
First, store the _bookdown.yml file you described in the same folder as the blog post source .Rmd file, e.g. content/post/_bookdown.yml if your file is at content/post/my_post.Rmd.
Then, add _bookdown.yml to the list of ignoreFiles in your config.toml so that Hugo doesn't move _bookdown.yml to the public directory.
This works because blogdown::html_page() is based on bookdown::html_document2(), which will pick up the _bookdown.yml in the same directory of the source Rmd. I don't think it's possible to set this globally from your blogdown root dir, but if you store all your posts in content/post it's basically the same thing.
Like the title says I want to create a folder in a specific directory with Adobe Air.
If I use static methods of File like File.userDirectory works fine but I need to give the choice to select the directory.
I am trying this:
file.addEventListener(Event.SELECT, dirSelected);
file.browseForDirectory("Select a directory");
function dirSelected(e:Event):void {
trace(file.nativePath);
file.resolvePath("new_folder");
file.createDirectory();
}
Nothing happens
"resolvePath: Creates a new File object with a path relative to this File object's path, based on the path parameter (a string)."
So:
var newDir:File = file.resolvePath("new_folder");
newDir.createDirectory();
If in Yii 1.1.x there is some extension, to create valid file system(linux) name from object title with unique name, like a slug, but with unique name in given directory ?
I mean I want to save file on disk with name based on title of object.
Thanks!
Actually I would like a bit more :
1) In title of object all illigel chars(for Linux/windows OS) and space must be converted to '-'
2) if there is such file add valid counter for it , like "_45"
Maybe that not yii extension, but some php function.
The simplest way - you can add object id to prefix of file. Then your file names always be uniqueness. For example:
1-title-first
2-title-first
3-title-second
you can use php own uniqueid() to generate unique ids!
$title = uniqid('wp_'); // have wp_ prefixed for title
I would like to get all the files that a sub-folder holds in a string array.
So, I have tried something like the following:
var IOstore = IsolatedStorageFile.GetUserStoreForApplication();
string searchpath = System.IO.Path.Combine("product", ProductName);
string filesInSubDirs[] = IOstore.GetFileNames(searchpath);
But I got all the files in the "product" folder. I have also tried with "productname" only as the parameter.
Thanks for your help.
The search pattern for a sub-folder needs to include "*.*" at the end to pattern match any file, which would make your code something like the following:
var IOstore = IsolatedStorageFile.GetUserStoreForApplication();
string searchpath = System.IO.Path.Combine("product", ProductName);
searchpath = string.Format("{0}\\*.*", searchpath);
string filesInSubDirs[] = IOstore.GetFileNames(searchpath);
Something you might want to try. (this is sort of a left field answer, sorry). In my dropbox client http://sharpdropbox.codeplex.com/) I have a set of facades for System.IO.File, System.IO.FileInfo, System.IO.Directory, and System.IO.DirectoryInfo. They work pretty good and I have tested them.
Basically, you add a Using or Import for System.IO.IsolatedStorage and then PSFile, PSDirectory, PSFileInfo, or PSDirectoryInfo. It's saved me from having to remember all the nuances... for instance if you are querying a directory, it knows to add a slash, etc. BTW, the "PS" prefix stands for "Persisted Storage" which is what IsolatedStorage is sometimes called (starting them with an "I" implies they are interfaces.. and having no prefix makes things even more confusing).
Anyway, you can grab the code from source or I believe the last release had the DLLs for them (it's called something like "IsolatedStorageFacade-WP7")