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

[docs] CToSwift: Add ObjC properties section, finish swift_name section #27465

Merged
merged 2 commits into from Oct 2, 2019

Conversation

@jrose-apple
Copy link
Member

commented Oct 1, 2019

No description provided.

@varungandhi-apple

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2019

I keep seeing "New changes since you last viewed" even though I clicked "View changes" and approved it. 🤷‍♂

@jrose-apple

This comment has been minimized.

Copy link
Member Author

commented Oct 1, 2019

@swift-ci Please smoke test

@xymus
xymus approved these changes Oct 1, 2019
init(default: ())
```
A custom name on a method with one of Objective-C's subscript selectors (`objectAtIndexedSubscript:`, `objectForKeyedSubscript:`, `setObject:atIndexedSubscript:`, or `setObject:forKeyedSubscript:`) prevents that method from being imported as a subscript or used as the accessor for another subscript.

This comment has been minimized.

Copy link
@brentdax

brentdax Oct 1, 2019

Contributor

I think this is the only discussion of subscripts so far in this document?

It's worth noting somewhere (maybe not here) that only instance methods are eligible to be subscripts. This is because, although Objective-C sort of tries to allow subscripts on class methods, there's no actual way to call them as subscripts.

This comment has been minimized.

Copy link
@jrose-apple

jrose-apple Oct 1, 2019

Author Member

I think this is the only discussion of subscripts so far in this document?

Yeah, I haven't actually done the regular section on ObjC methods yet. It's the hardest section because of omit-needless-words, so I've been putting it off.

although Objective-C sort of tries to allow subscripts on class methods

I'm not quite sure what this means when it doesn't work, but sure. I think I'll just throw in the word "instance".

This comment has been minimized.

Copy link
@brentdax

brentdax Oct 1, 2019

Contributor

What I mean is that you can define an +objectAtIndexedSubscript:, but the instance you would call it on is just going to be Class because ObjC is never more specific than that, so you can't use subscript syntax with it in ObjC.

In any case, no need to state a justification.

This comment has been minimized.

Copy link
@jrose-apple

jrose-apple Oct 1, 2019

Author Member

Class behaves like id, so it ought to work as long as anyone has declared a class subscript accessor. Also literally referencing the class ought to work (NSFoo[0]), the way it does for properties (even before class properties were a thing).

This comment has been minimized.

Copy link
@brentdax

brentdax Oct 2, 2019

Contributor

I don't think you can use subscripts on id, either. I think I actually wrote some ObjC code that tried to declare and use a class subscript and it didn't work.

This comment has been minimized.

Copy link
@jrose-apple

jrose-apple Oct 2, 2019

Author Member

No, that one works.

@import Foundation;

void test(id foo) {
  (void)foo[0];
}
jrose-apple added 2 commits Oct 1, 2019
Struct/union fields, ObjC properties, ObjC methods
Fairly simple except in the few cases they aren't.
@jrose-apple jrose-apple force-pushed the jrose-apple:properties-of-properties branch from f332ffd to 1bb666a Oct 2, 2019
@jrose-apple

This comment has been minimized.

Copy link
Member Author

commented Oct 2, 2019

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit a59f438 into apple:master Oct 2, 2019
2 checks passed
2 checks passed
Swift Test Linux Platform (smoke test)
Details
Swift Test OS X Platform (smoke test)
Details
@jrose-apple jrose-apple deleted the jrose-apple:properties-of-properties branch Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.