• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Swift - internal class conforming to public protocol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift - internal class conforming to public protocol


  • Subject: Re: Swift - internal class conforming to public protocol
  • From: Roland King <email@hidden>
  • Date: Wed, 25 Nov 2015 16:49:15 +0800

> On 25 Nov 2015, at 16:30, Andreas Mayer <email@hidden> wrote:
>
>
>> Am 25.11.2015 um 08:56 schrieb Quincey Morris <email@hidden>:
>>
>>> That's explained in "Using Swift with Cocoa and Objective-C":
>>>
>>> "The compiler does not automatically insert the @objc attribute for declarations marked with the private access-level modifier.”
>>
>> That can’t be the full explanation, because the other private method doesn’t produce an error, Roland said.
>
> I can't replicate that behavior.
>
> This doesn't work:
>
> // Roland's protocol must be marked @objc since it has optional requirements.
>
> @objc public protocol PublicProtocol {
> 	func someFunction()
> 	// ...
> }
>
> private class SomeClass: NSObject, PublicProtocol {
> 	func someFunction() {
> 		// implementation
> 	}
> }

here’s my distilled example

import CoreBluetooth
private class Bananas : NSObject, CBCentralManagerDelegate
{
	func centralManagerDidUpdateState(central: CBCentralManager)->Void {
		// do nothing, I care little for your state
	}

	func centralManager(central: CBCentralManager, didRetrievePeripherals peripherals: [CBPeripheral])
	{
		// do nothing, you retrieved peripherals, I don't care
	}
}

with the private designator, you get a warning on the second function about optionality and @obcj, and an error, not on the first, but on the entire class telling you the first function needs to be marked @objc, but not for optionality reasons, just says that the candidate is not @objc but the protocol requires it. So they both need objc, but for slightly different reasons, and the errors are reported in slightly different ways

change it to internal, no errors, no warnings, as now expected

change it to public and you get errors on both functions telling you to make them public, also as now expected.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Swift - internal class conforming to public protocol (From: Roland King <email@hidden>)
 >Re: Swift - internal class conforming to public protocol (From: Andreas Mayer <email@hidden>)
 >Re: Swift - internal class conforming to public protocol (From: Roland King <email@hidden>)
 >Re: Swift - internal class conforming to public protocol (From: Andreas Mayer <email@hidden>)
 >Re: Swift - internal class conforming to public protocol (From: Marco S Hyman <email@hidden>)
 >Re: Swift - internal class conforming to public protocol (From: Quincey Morris <email@hidden>)
 >Re: Swift - internal class conforming to public protocol (From: Andreas Mayer <email@hidden>)

  • Prev by Date: Re: Swift - internal class conforming to public protocol
  • Next by Date: Re: Why can't a Swift method directly access a static member?
  • Previous by thread: Re: Swift - internal class conforming to public protocol
  • Next by thread: Re: Swift - internal class conforming to public protocol
  • Index(es):
    • Date
    • Thread