Вопросы по тегу: access-modifiers

(2)

Инициализатор недоступен из-за «внутреннего» уровня защиты

У меня есть несколько протоколовСтратегия входаpublic protocol LoginStrategy { func login(_ viewController: UIViewController) func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ()) func createLoginButton(_ frame: CGRect, withCompletionHandler completionHandler: @escaping (_ loginButton: UIView) -> ()) func getUserId() -> String } и два класса:ЛогинПровайдерpublic class LoginProvider { public let strategy: LoginStrategy public func login(_ viewController: UIViewController) { return self.strategy.login(viewController) } public func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ()) { return self.strategy.getUserInfo(withCompletionHandler: completionHandler) } public func createLoginButton(_ frame: CGRect, withCompletionHandler completionHandler: @escaping (_ loginButton: UIView) -> ()) { return self.strategy.createLoginButton(frame, withCompletionHandler: completionHandler) } public func getUserId() -> String { return self.strategy.getUserId() } public init(strategy: LoginStrategy) { self.strategy = strategy } } Стратегия входа в Facebookimport Foundation import FacebookCore import FacebookLogin public class FacebookLoginStrategy: LoginStrategy { public var grantedPermissions: Set? = nil public var declinedPermissions: Set? = nil public var userId: String = "" public func login(_ viewController: UIViewController) { let loginManager = LoginManager() let permissions: [ReadPermission] = [.publicProfile, .userFriends, .email] loginManager.logIn(permissions, viewController: viewController) { loginResult in switch loginResult { case .failed(let error): print(error) case .cancelled: print("User cancelled login.") case .success(let grantedPermissions, let declinedPermissions, let accessToken): self.userId = accessToken.userId ?? "" self.grantedPermissions = grantedPermissions self.declinedPermissions = declinedPermissions print("Logged in!") } } } public func getUserId() -> String { return userId } public func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ()) { let request = GraphRequest(graphPath: "me", parameters: ["fields":"email, name"], accessToken: AccessToken.current, httpMethod: .GET, apiVersion: FacebookCore.GraphAPIVersion.defaultVersion) request.start { (response, result) in switch result { case .success(let value): print(value.dictionaryValue) completionHandler(value.dictionaryValue) case .failed(let error): print(error) } } } public func createLoginButton(_ frame: CGRect, withCompletionHandler completionHandler: @escaping (_ loginButton: UIView) -> ()) { let permissions: [ReadPermission] = [.publicProfile, .userFriends, .email] let loginButton = LoginButton(readPermissions: permissions) loginButton.frame = frame completionHandler(loginButton) } } В моем ViewController:Когда я использую:let facebookLoginProvider = LoginProvider(strategy: FacebookLoginStrategy()) Там написано: «FacebookLoginStrategy» недоступен из-за «внутренней» защиты уровень
K

Khuong

5 лет назад

Ответов: 3

Does Java have a "private protected" access modifier?

I have seen some references refer to a access modifier in Java called private protected (both words together):private protected someMethod() { } One of the pages I found referring to this is here. My school lesson also referred to this access modifier (and said it exists). Using it, however, results in an error in the Java language.I tried with both variables and methods and I'm pretty sure it doesn't exist, but I want an explanation of what happened. Was it considered, then rejected? Or did it get removed in a newer version of Java?Edit: I am not looking for info about the protected keyword.
u

user6754053

5 лет назад

Ответов: 5

2022 WebDevInsider