<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Why would you need to change the call sites? If you have existing Swift code that calls these Obj-C entrypoints, you simply wouldn't mark them as `public(objc)` but would just leave them as, well, public API.<br></div>
<div> </div>
<div>There's nothing about this proposal that <i>forces</i> you to use it. You can continue to expose API to Obj-C the same way you do today. But the entire point of <span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">public(objc)</span> is to expose API to Obj-C <i>without</i> exposing it to Swift as well (because there's already a better API exposed to Swift).<br></div>
<div> </div>
<div>-Kevin Ballard<br></div>
<div> </div>
<div>On Tue, Jan 5, 2016, at 03:15 PM, Félix Cloutier wrote:<br></div>
<blockquote type="cite"><div>I can't agree to that. If I gradually port an API from Objective-C to Swift and at some point decide to go back to make a Swiftier entry point, I'll be very disappointed that I need to change the call sites to the Objective-C-compatible one, not because something will break, but because the Swift mailing list thought Swift would be purer if I couldn't use it.<br></div>
<div><div><div><div> </div>
<div><span class="colour" style="color:rgb(0, 0, 0)"><span class="font" style="font-family:'Lucida Grande'"><span class="size" style="font-size:12px">Félix</span></span></span><br></div>
</div>
<div> </div>
<div><blockquote type="cite"><div>Le 5 janv. 2016 à 17:56:42, Kevin Ballard <<a href="mailto:kevin@sb.org">kevin@sb.org</a>> a écrit :<br></div>
<div> </div>
<div><div><div>Code completion aside, it just makes me really unhappy to expose a Swift API that nobody should <i>ever</i> call from Swift. I just don't want to have that API be accessible at all when it only exists to serve as the Obj-C entrypoint.<br></div>
<div> </div>
<div>-Kevin Ballard<br></div>
<div> </div>
<div>On Tue, Jan 5, 2016, at 02:55 PM, Félix Cloutier wrote:<br></div>
<blockquote type="cite"><div>.NET has an <a href="https://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute(v=vs.110).aspx">EditorBrowsable</a> attribute that controls whether things appear in autocomplete or not. I think that this alternative deserves some consideration.<br></div>
<div> </div>
<div><div>It clearly won't have identical semantics, but I think that it would be a little more graceful and much less involved. This solution only needs a new attribute and SourceKit changes.<br></div>
<div><div><div> </div>
<div><span style=""><span class="font" style="font-family:'Lucida Grande'"><span class="size" style="font-size:12px">Félix</span></span></span><br></div>
</div>
<div> </div>
<div><blockquote type="cite"><div>Le 5 janv. 2016 à 15:23:55, Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> a écrit :<br></div>
<div> </div>
<div><div><div>Proposal PR submitted as <a href="https://github.com/apple/swift-evolution/pull/85">https://github.com/apple/swift-evolution/pull/85</a><br></div>
<div> </div>
<div>-Kevin Ballard<br></div>
<div> </div>
<div>On Tue, Dec 15, 2015, at 11:18 AM, Kevin Ballard wrote:<br></div>
<blockquote type="cite"><div>When writing ObjC code, there's a macro NS_REFINED_FOR_SWIFT (or __attribute__((swift_private))) that mangles the name when imported into Swift. The intention here is to hide an API from normal Swift usage (but still make it callable) so that a better Swift API can be written around it.<br></div>
<div> </div>
<div>But there's no facility for doing this in reverse. You can expose Swift APIs to ObjC, but the API has to be ObjC-compatible. Which means that if you have a non-ObjC-compatible API, you have to write a separate API to expose it to ObjC, and this separate API now shows up in the Swift API too.<br></div>
<div> </div>
<div>I think the simplest way to fix this is to allow for a modifier public(objc) (following the syntax of private(set)). The only thing this modifier does is ensure the declaration gets added to the generated header as if it were public (or—for apps—internal). If the declaration is not marked as @objc then it would emit an error (it could imply @objc but it feels weird to me to have an access control modifier do that). If the declaration is already public (but not internal, so the same source can be used in apps and libraries) it will emit a warning.<br></div>
<div> </div>
<div>Armed with this new modifier, I can start to write code like<br></div>
<div> </div>
<div>class MyClass: NSObject {<br></div>
<div> func foo<T>(x: T) { ... }<br></div>
<div>}<br></div>
<div> </div>
<div>extension MyClass {<br></div>
<div> @objc(foo) public(objc) private func __foo(x: AnyObject) { ... }<br></div>
<div>}<br></div>
<div> </div>
<div>When used on a property that already has private(set), the public(objc) modifier will only apply to the getter (e.g. the private(set) takes precedence for the setter).<br></div>
<div> </div>
<div>Alternatives:<br></div>
<div> </div>
<div>* Add a new attribute @export_objc that has the same behavior.<br></div>
<div> </div>
<div>* Change the @objc attribute to take an optional second argument, which may be the token "exported", as in @objc(foo,exported). When using the "exported" token, the selector portion is required. We could possibly support an empty selector to indicate the default, as in @objc(,exported), but that looks odd.<br></div>
<div> </div>
<div>My preference is for public(objc) as proposed as it matches more closely with the intended behavior, which is "this API is private in Swift and public in ObjC".<br></div>
<div> </div>
<div>-Kevin Ballard<br></div>
</blockquote><div>_______________________________________________<br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</div>
</blockquote></div>
</div>
</div>
</blockquote><div> </div>
</div>
</div>
</blockquote></div>
</div>
</div>
</blockquote><div> </div>
</body>
</html>