I'd like to use GKSession in one of my swift file. But there is a problem to do so. Here is the error message:
/Users/Desktop/Snap/Snap/MatchmakingServer.swift:15:1: Type
'MatchmakingServer' does not conform to protocol 'NSObjectProtocol'
Here is my code:
class MatchmakingServer : GKSessionDelegate {
I have no idea what does this mean and how to solve the issue. Can anybody help? Thanks
Related
so i have this weird problem that's been bugging me for the last few hours.
I have a framework in which I created a protocol named ChatDelegate (code bellow)
public protocol ChatDelegate: class {
func chat(_ chatCollectionView: UICollectionView, didSelect message: Message)
}
and a ViewController (not in the framework), which conforms to the ChatDelegate, like so
extension ChatContainerViewController: ChatDelegate {
func chat(_ chatCollectionView: UICollectionView, didSelect message: Message) {
print("did select")
}
}
but the compiler still complains that the ChatContainerViewController does not conform to the protocol and I don't understand why?? The function has the exact same header (I also tried putting public in front ...didn't help).
Any help would be much appreciated.
UPDATE
I figured it out. The problem was that I had Message class in my project and in the framework and the compiler didn't know which one to choose. Adding ModuleName in front (ModuleName.Message) fixed it. :D
I had the same issue. The file that defined the protocol had a target membership in both the framework and the application targets. I solved the issue by making the file that defined the protocol only have a target membership in the framework and then adding an import <FrameworkName> to the code in the application target that needed to use the protocol.
I am trying to implement the following method in swift:
From the class FLIROneSDKImageReceiverDelegate, which is subclassed inside my ViewController class as so:
class ViewController: UIViewController, FLIROneSDKImageReceiverDelegate,
FLIROneSDKStreamManagerDelegate,
FLIROneSDKImageEditorDelegate{
Note that I have already created a bridging header etc.
In the FLIROneSDKImageReceiverDelegate header file:
- (void) FLIROneSDKDelegateManager:(FLIROneSDKDelegateManager *)delegateManager didReceiveBlendedMSXRGBA8888Image:(NSData *)msxImage imageSize:(CGSize)size;
Am I wrong in thinking that this is the correct way to implement this function?
func FLIROneSDKDelegateManagerdidReceiveBlendedMSXRGBA8888ImageimageSize(delegateManager: FLIROneSDKDelegateManager!, msxImage: NSData, size: CGSize){
Note that FLIROneSDKDelegateManager is a class.
Off the top of my head, but try this:
func FLIROneSDKDelegateManager(delegateManager: FLIROneSDKDelegateManager!, didReceiveBlendedMSXRGBA8888Image msxImage: NSData!, imageSize size: CGSize) {
// method imp
}
#Laxsnor's solution in the comments on the answer by #aaron-wojnowski helped me too, thanks both.
To consolidate:
The problem is a conflict created by the name FLIROneSDKDelegateManager being used as a both a class name and a function name - which seems to be OK in Objective-C but not in Swift.
Replacing the class FLIROneSDKDelegateManager with NSObject in the function parameter seems to solve the problem without side-effects. This has to be done in both the Objective-C protocol header file and the Swift delegate class source file.
NOTE I also found this same solution applied more broadly to Swift-ify the entire FLIROneSDK at https://github.com/jruhym/flirmebaby.
Happy developing for FLIROne on Swift. (I'm new to FLIROne and relatively new to Swift so apologies if my language isn't quite precise enough.)
I'm learning how to program in Swift.
At one step in the iOS Developer Library
https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson3.html#//apple_ref/doc/uid/TP40015214-CH22-SW1
it tells me to add the command:
nameTextField.delegate = self
After entering the Command a Error pops up saying:
Value of type 'UIStackView' has no Member 'delegate'
Please someone have a solution?
Thank you in advance.
You should try adding the UITextFieldDelegate protocol.
I have declared error type
enum UserServicesError: ErrorType {
case UserNotLogged
}
but I get an error
Argument type 'UserServicesError' does not conform to expected type 'ErrorType'
Type 'UserServicesError' does not conform to protocol 'RawRepresentable'
Any idea y? Official documentation says that this declaration is sufficient.
Apple Swift 2.1 Error handling documentation
I've finally figure it out. I had declared enum ErrorType in objective-c shared class from pre-swift ages.
typedef NS_ENUM(NSUInteger, ErrorType) {
...
};
I would expect to see a Redefined type error rather than does not conform to protocol 'RawRepresentable'
Are you by any chance using UserServicesError with Cocoa classes? If so, the Errors subsection of Using Swift with Cocoa and Objective-C guide suggests it should be declared like this:
#objc enum UserServicesError: Int, ErrorType {
case UserNotLogged
}
The #objc designation is needed for any protocols that interact with Objective-C Cocoa objects. Conforming to Int (or some other RawRepresentable-conforming type) gets you RawRepresentable conformance automatically (vs. leaving it a pure Swift enum).
I hope this helps. If it does, let me know if it was one, the other, or both needed to fix it. I'm curious. :-)
I am trying to use the BoxSearchRequestBuilder class to be able to perform a search in Box via the iOS SDK (v2). When I try to instantiate a BoxSearchRequestBuilder instance with its initializer, I get a compiler error.
What I am trying to do:
BoxSearchRequestBuilder* builder = [[BoxSearchRequestBuilder alloc] initWithSearch:#"123" queryStringParameters:#{#"content_types" : #"tags"}];
The error:
receiver 'BoxSearchRequestBuilder' for class message is a forward declaration or
receiver type 'BoxSearchRequestBuilder' for instance message is a forward declaration.
Basically the BoxSearchRequestBuilder class is declared via a forward declaration (#BoxSearchRequestBuilder), so I cannot directly access its properties/initializers.
I can fix the error by going to the iOS SDK class BoxSearchResourceManager and changing the forward declaration to an import statement:
#import "BoxSearchRequestBuilder.h"
//#class BoxSearchRequestBuilder;
However, I don't think I should be doing this. Are there any other alternatives? The rest of the API works fine.
Thanks for flagging this.
It has been fixed thanks to your feedback in this change:
https://github.com/box/box-ios-sdk-v2/commit/67064ea1f0c1aff040fba1e249b9f550281c01e2
feel free to file issues on SDK github page.