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

[TIMOB-23495] iOS: Add Ti.Filesystem.File "parent" property (parity) #9285

Merged
merged 11 commits into from
Nov 9, 2017
26 changes: 18 additions & 8 deletions apidoc/Titanium/Filesystem/File.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,20 @@ methods:
returns:
type: Array<String>
- name: getParent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we actually need to deprecate this and not just remove it? Can we have a parent property that holds a Ti.Filesystem.File return value, but also have a getParent() method that returns the path of the parent as a String?

This is a breaking change, so we need to deprecate for one major version first... I assume there are apps out there relying on this getter existing and returning a string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only removed it because the getter is generated automatically by using - (NSString *)parent. But I assume we could match Android's behavior here whereby getParent returns a file and parent a string. @infosia how does Windows behave here? Although I don't like that the getter of a property returns something different (oddly, I'd rather match the most-useful behavior). Maybe deprecate the difference on Android?

summary: Returns the path of the parent directory holding the file identified by this
file object, as a String **or** as a `File` object.
summary: |
Returns the path of the parent directory holding the file identified by this
file object, as a String (deprecated) **or** as a `File` object.
description: |
On iOS, this method returns the path of the parent directory as a String.

Android supports a [parent](Titanium.Filesystem.File.parent) property, which
is a `File` object representing the parent directory path. The `getParent` method
on Android is a getter for the `parent` property, so it returns a `File` object
rather than a String.
Prior to Titanium SDK 7.0.0, on iOS this method returned the path of the parent
directory as a String. Since Titanium SDK 7.0.0, this method has been deprecated
in favor of the <Titanium.Filesystem.File.parent> property and will return
a <Titanium.Filesystem.File> reference in the future as well.
deprecated:
since: "7.0.0"
notes: |
Use the <Titanium.Filesystem.File.parent> property to receive a `File`
reference instead. If you wish to receive the path, use the `nativePath`
property of that reference instead.
returns:
- type: String
- type: Titanium.Filesystem.File
Expand Down Expand Up @@ -354,8 +359,13 @@ properties:
method to obtain a plain file path for use with native modules.
type: String
permission: read-only

- name: parent
summary: A `File` object representing the parent directory of the file identified by this object.
description: |
iOS platform-note: Prior to Titanium SDK 7.0.0, this method returned the
path of the parent directory as a String. Since Titanium SDK 7.0.0 it
returnes a <Titanium.Filesystem.File> reference for parity wih Android and Windows.
type: Titanium.Filesystem.File
permission: read-only
platforms: [android]
Expand Down
8 changes: 7 additions & 1 deletion iphone/Classes/TiFilesystemFileProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,17 @@ - (id)extension:(id)args
return [path pathExtension];
}

- (id)getParent:(id)args
- (NSString *)getParent:(id)args
{
DEPRECATED_REPLACED(@"Filesystem.File.getParent()", @"7.0.0", @"Filesystem.File.parent");
return [path stringByDeletingLastPathComponent];
}

- (TiFilesystemFileProxy *)parent
{
return [[[TiFilesystemFileProxy alloc] initWithFile:[path stringByDeletingLastPathComponent]] autorelease];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgtcoolguy Sorry to bug you on this, but to confirm:

  1. Deprecate getParent() for parity with other platforms
  2. Introduce parent property that works the same across all platforms
  3. In 8.0.0+, remove the manual getParent accessor, so getParent() will use the computed getter that matches all platforms without a deprecation.

}

- (id)name
{
return [path lastPathComponent];
Expand Down