protocols

Protocol Extension Initializer

喜欢而已 提交于 2019-12-17 19:35:01
问题 I would like to know what the protocol equivalent is for an initializer in a simple class that only contains initializing functionality and is only intended to be extended in a concrete class. So probably the easiest is to show the code - I'm looking for the protocol extension equivalent of the following: import UIKit class Thing { var color:UIColor init(color:UIColor) { self.color = color } } class NamedThing:Thing { var name:String init(name:String,color:UIColor) { self.name = name super

How to check if website has http/2 protocol support

拟墨画扇 提交于 2019-12-17 19:16:38
问题 There is a lot of topic about http/2 protocol, but I wonder if there is a working website with this protocol. i.e. We can decide to use http:// or https:// but how to write a http/2 request? I am aware that this protocol depends on server capability, but can not find a way to check if some website e.g. google.com has http2 support enabled. As I can see in this picture, all modern browsers support this protocol. I have not seen any link that could look like a new generation protocol. My

Using some protocol as a concrete type conforming to another protocol is not supported

情到浓时终转凉″ 提交于 2019-12-17 17:36:44
问题 I’m trying to mix generics with protocols and I’m getting a really hard time xD I have certain architecture implemented in an Android/Java project, and I’m trying to rewrite it to fit it in a swift/iOS project. But I’ve found this limitation. ProtocolA protocol ProtocolA { } ProtocolB protocol ProtocolB : ProtocolA { } ImplementProtocolA class ImplementProtocolA <P : ProtocolA> { let currentProtocol : P init(currentProtocol : P) { self.currentProtocol = currentProtocol } } ImplementProtocolB

Swift 3 unable to append array of objects, which conform to a protocol, to a collection of that protocol

别说谁变了你拦得住时间么 提交于 2019-12-17 16:59:48
问题 Below I have pasted code which you should be able to paste into a Swift 3 playground and see the error. I have a protocol defined and create an empty array of that type. I then have a class which conforms to the protocol which I try to append to the array but I get the below error. protocol MyProtocol { var text: String { get } } class MyClass: MyProtocol { var text = "Hello" } var collection = [MyProtocol]() var myClassCollection = [MyClass(), MyClass()] collection.append(myClassCollection)

Swift: Is it possible to add a protocol extension to a protocol?

一个人想着一个人 提交于 2019-12-17 16:28:19
问题 Lets say I have two protocols: protocol TheirPcol {} protocol MyPcol { func extraFunc() } What I want to do is to create a protocol extension for 'TheirPcol' which lets extraFunc() work on anything which conforms to 'TheirPcol'. So something like this: extension TheirPcol : MyPcol { // Error 'Extension of protocol 'TheirPcol' cannot have an inheritance clause. func extraFunc() { /* do magic */} } struct TheirStruct:TheirPcol {} let inst = TheirStruct() inst.extraFunc() The kicker in this is

why does java's URL class not recognize certain protocols?

风流意气都作罢 提交于 2019-12-17 16:27:15
问题 URL u=new URL("telnet://route-server.exodus.net"); This line is generating : java.net.MalformedURLException: unknown protocol: telnet And i encounter similar problems with other URLs that begin with "news://" These are URLs extracted from ODP , so i dont understand why such exceptions arise.. 回答1: Issue Java throws a MalformedURLException because it couldn't find a URLStreamHandler for that protocol. Check the javadocs of the constructors for the details. Summary: Since the URL class has an

Reasons to include function in protocol definition vs. only defining it in the extension?

风流意气都作罢 提交于 2019-12-17 14:05:06
问题 Take the following protocol and extension: protocol ProtocolA { func myFunc() } extension ProtocolA { func myFunc() { print("Default ProtocolA implementation.") } } What is the difference, if any, between that and leaving the function out of the protocol definition entirely, like this: protocol ProtocolB { } extension ProtocolB { func myFunc() { print("Default ProtocolB implementation.") } } I found one difference. If I define a struct that overrides the default implementation, I can only

Reasons to include function in protocol definition vs. only defining it in the extension?

隐身守侯 提交于 2019-12-17 14:04:33
问题 Take the following protocol and extension: protocol ProtocolA { func myFunc() } extension ProtocolA { func myFunc() { print("Default ProtocolA implementation.") } } What is the difference, if any, between that and leaving the function out of the protocol definition entirely, like this: protocol ProtocolB { } extension ProtocolB { func myFunc() { print("Default ProtocolB implementation.") } } I found one difference. If I define a struct that overrides the default implementation, I can only

Cannot find protocol declaration for

佐手、 提交于 2019-12-17 10:58:36
问题 I have two objects, both of which are view controllers. The first (Ill call it viewController1) declares a protocol. The second (which unsurprisingly I will name viewController2) conforms to this protocol. XCode is giving me a build error of: 'Cannot find protocol declaration for viewController1' I have seen various questions on this subject and I am certain it is to do with a loop error, but I just can't see it in my case... Code below.. viewController1.h @protocol viewController1Delegate;

access to file using Java with Samba JCIFS

可紊 提交于 2019-12-17 04:55:13
问题 I have a question about accessing file with Samba JCIFS. So there is a server I want to access, let's call it server.unv.edu and the workgroup is WKGRP. there is a share in this server: \\server.unv.edu\pcb$ the way I am trying to access to the server is : public class SMBAuthenticator extends NtlmAuthenticator{ private String username = "username"; private String password = "password"; private String domain = "smb://server.unv.edu/WKGRP/"; public SMBAuthenticator(){ NtlmAuthenticator