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

Rename Item API #67

Open
ghost opened this issue Jun 1, 2018 · 7 comments
Open

Rename Item API #67

ghost opened this issue Jun 1, 2018 · 7 comments

Comments

@ghost
Copy link

ghost commented Jun 1, 2018

Hi @JohnSundell ,

I'm enjoying the Files API and I'm glad I can help in any way. Even if my contributions are just discussion points that lead to potential pull requests from others.

I have, yet another, discussion point to raise. I hope you don't mind.

RenameItem

Unless I examine the source, it's not clear here if newName is name only or name + extension.

public func rename(to newName: String, keepExtension: Bool = true) throws

Further, I currently have a situation where the above API is inconvenient.

At the moment I'm unpacking a .pdf file from a CKAsset instance (CloudKit).

  1. After digging through the asset, I find a file named asdkfjkajsdkfha.owkheorhjdsf
  2. The file is stored in temp dir so I need to also move it.
  3. I want the file to have a different name, including a new .pdf extension.

Perhaps, we might want to have something like the following?

public func rename(to newName: String) throws

And maybe we can examine the name to see if it contains a "."

Do you think this is a valid issue and do you have any ideas on this?

@clayellis
Copy link
Contributor

We could remove all ambiguity and assumptions and be more explicit:

enum ExtensionOption {
    case keep
    case remove
    case `extension`(String)
}

public func rename(to name: String, extension: ExtensionOption) throws

And provide a convenience overload that would take a String

public func rename(to name: String, extension: String) throws {
    try rename(to: name, extension: .extension(extension))
}

That way name and extension are both treated as separate parts.

What do you think @rob-nash?

@ghost
Copy link
Author

ghost commented Jun 1, 2018

Ye that's a good idea. How about.

enum ExtensionOption {
    case keep
    case remove
    case change(to: String)
}

Is to: possible ?

@clayellis
Copy link
Contributor

I like that. Yeah, it's possible. And it's fantastic.

@clayellis
Copy link
Contributor

clayellis commented Jun 1, 2018

In order to not break existing code, we'd have to provide a default parameter:

public func rename(to name: String, extension: ExtensionOption = .keep) throws

Which would cover the case where users had used:

try someFile.rename(to: "SomeOtherFile") // without keepExtension

And then deprecate the previous signature. The previous method can be kept around (and would defer to the new method) but its default value of keepExtension = true has to be removed to avoid ambiguity.

@ghost
Copy link
Author

ghost commented Jun 11, 2018

hi @clayellis how might I get in touch with you directly? Are you on twitter?

@clayellis
Copy link
Contributor

clayellis commented Jun 13, 2018

@rob-nash yep! https://twitter.com/clay_ellis DMs are open. Sorry for the late response — just finished packing/moving into a new house.

@ghost
Copy link
Author

ghost commented Jun 27, 2018

Hi @clayellis I think DM's only work if you follow me. I'm not fishing for followers 😜 🙄

Email? robscode@icloud.com

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

Successfully merging a pull request may close this issue.

1 participant