protocols

Registering and using a custom java.net.URL protocol

谁都会走 提交于 2019-12-17 03:56:26
问题 I was trying to invoke a custom url from my java program, hence I used something like this: URL myURL; try { myURL = new URL("CustomURI:"); URLConnection myURLConnection = myURL.openConnection(); myURLConnection.connect(); } catch (Exception e) { e.printStackTrace(); } I got the below exception: java.net.MalformedURLException: unknown protocol: CustomURI at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at com.demo.TestDemo.main(TestDemo.java

Registering and using a custom java.net.URL protocol

只谈情不闲聊 提交于 2019-12-17 03:56:19
问题 I was trying to invoke a custom url from my java program, hence I used something like this: URL myURL; try { myURL = new URL("CustomURI:"); URLConnection myURLConnection = myURL.openConnection(); myURLConnection.connect(); } catch (Exception e) { e.printStackTrace(); } I got the below exception: java.net.MalformedURLException: unknown protocol: CustomURI at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at com.demo.TestDemo.main(TestDemo.java

How to detect browser's protocol handlers?

不羁的心 提交于 2019-12-16 20:13:43
问题 I have created a custom URL protocol handler. http:// mailto:// custom:// I have registered a WinForms application to respond accordingly. This all works great. But I would like to be able to gracefully handle the case where the user doesn't have the custom URL protocol handler installed, yet. In order to be able to do this I need to be able to detect the browser's registered protocol handlers, I would assume from JavaScript. But I have been unable to find a way to poll for the information. I

How can I use Type Erasure with a protocol using associated type

感情迁移 提交于 2019-12-14 00:26:29
问题 I am working on a project that has a network client that basically follows the below pattern. protocol EndpointType { var baseURL: String { get } } enum ProfilesAPI { case fetchProfileForUser(id: String) } extension ProfilesAPI: EndpointType { var baseURL: String { return "https://foo.bar" } } protocol ClientType: class { associatedtype T: EndpointType func request(_ request: T) -> Void } class Client<T: EndpointType>: ClientType { func request(_ request: T) -> Void { print(request.baseURL) }

Protocol type cannot be instantiated

五迷三道 提交于 2019-12-13 18:31:06
问题 Consider the following code: protocol Color { var color: UIColor { get } } struct Ball : Color { var color: UIColor } let ball = Ball(color: .white) print(ball) This works, and results in: Ball(color: UIExtendedGrayColorSpace 1 1) Now, I would like to make a function in the protocol, that given an array of colors, returns an array of items (balls, or any other type that conforms to Color ) with that color: extension Color { func multipleColors(colors: [UIColor]) -> [Color] { var coloredItems

iOS- protocols and delegates on the example

做~自己de王妃 提交于 2019-12-13 15:06:16
问题 Ok, i was searching but there wasn't any method that was working for me. Following code bases on many tutorials and Apple documentation, but i can't get it to work. Can anybody help please? Code is crashing at: obj.delegatee = self; (in class B.h), also methods respondsToSelector and performSelector:withObject aren't recogized. I want to set delegate object, on which there will be a method called when we tap on particular picture. class A.h: @interface AViewController : UIViewController

EXC_BAD_ACCESS error for NSManagedObject implementing a protocol in Swift

风流意气都作罢 提交于 2019-12-13 14:32:36
问题 I have the following two methods: func isAuthenticated() -> Bool { var currentUser: CurrentUser? = self.getCurrentUser() if currentUser == nil { return false } self.token = getUserToken(currentUser!.username) if self.token == nil { return false } if !tokenIsValidForUser(self.token!, user: currentUser!) { return false } return true } func tokenIsValidForUser(token: AuthenticationToken, user: UserObject) -> Bool { if token.username != user.username { return false } return true } When I call

Obj-C header file not recognizing protocol from Swift class

谁说胖子不能爱 提交于 2019-12-13 14:14:18
问题 I've defined a protocol in a Swift file that isn't being recognized by an Obj-C header file. MainViewController.h #import "AppDelegate.h" @interface MainViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, AnotherViewControllerDelegate> @end In th file above, I'm getting the following error: Cannot find protocol declaration for "AnotherViewControllerDelegate"; did you mean "UIPageViewControllerDelegate"? MainViewController.m #import "MainViewController.h"

where Self: UIViewcontroller -> Compiler thinks I am dealing with a non-AnyObject instance [duplicate]

穿精又带淫゛_ 提交于 2019-12-13 08:14:19
问题 This question already has an answer here : Swift protocol with “where Self” clause (1 answer) Closed last year . This is my code public protocol MyProtocol where Self: UIViewController { var money: Int { get set } } public extension MyProtocol { func giveMoney() { // <-- ERROR: Left side of mutating operator isn't mutable: 'self' is immutable money += 1 } } This error shouldn't be thrown right? Every conforming instance of this protocol is a UIViewController , therefore a subclass of

Objective-C constants in protocol

送分小仙女□ 提交于 2019-12-13 07:32:29
问题 In my objective-c project, I have a protocol like this: @protocol MyProtocol -(id) get:(NSString *) key; -(void) set:(NSString *) key withValue:(id) value; -(NSValue *) getSize; -(void) setSize:(NSValue *) value; -(NSValue *) getBounds; -(void) setBounds:(NSValue *) value; @end OBJC_EXPORT const NSString *MYPROTOCOL_SIZE; OBJC_EXPORT const NSString *MYPROTOCOL_BOUNDS; And basically, those specific methods ( getSize , getBounds , setSize , setBounds ) are supposed the value that is supposed to