Xcode reports CBCentralManagerDelegate as not found - objective-c

I need some kind of advise
I am trying to implement Unity BLE Ios plugin. I've got issue while I am trying to build project in xcode:
Unknown class name 'CBCentralManagerDelegate'; did you mean 'CBCentralManager'?
Here is some part of generated header wrapper
#interface BLEManagerImpl : NSObject <CBCentralManagerDelegate>
- (NSString * _Nonnull)getDiscoveredDevices SWIFT_WARN_UNUSED_RESULT;
- (BOOL)startScanningWithTimeout:(double)timeout SWIFT_WARN_UNUSED_RESULT```

The CBCentralManagerDelegate is not import, you should
#import <CoreBluetooth/CoreBluetooth.h>

Related

different import statement in objective c

I was trying to debug a problem we were having in our React-Native on SDK
In our existing code, I see they have done
#import "CleverTap.h"
#import "CleverTapReactManager.h"
and docs says to do
#import <CleverTapSDK/CleverTap.h>
#import <CleverTapReact/CleverTapReactManager.h>
What is the difference between both the imports in swift? or they are the same?
#import "" first check the header in project folder then goes to system library, and the #import<> checks for system headers.
Read: https://swift007blog.wordpress.com/2017/01/13/include-vs-import/

Unknown class name PKPaymentAuthorizationViewControllerDelegate

Xcode error screenshot:
Working environment: Xcode 7.2, iOS 9.0, Mac OS X 10.11.3
I was working on my own Table View Controller to interact with Apple Pay and I copied the sample code from Apple.
In my PaymentTableViewController.swift:
import UIKit
import PassKit
import Contacts
class PaymentTableViewController: UITableViewController, PKPaymentAuthorizationViewControllerDelegate {
...
}
But then as it was auto-compiled into Objective-C to "Abletive(My project name)-Swift.h":
SWIFT_CLASS("_TtC8Abletive26PaymentTableViewController")
#interface PaymentTableViewController : UITableViewController <PKPaymentAuthorizationViewControllerDelegate>
Now and as it should be correct
But it says Unknown class name PKPaymentAuthorizationViewControllerDelegate and Unknown type name PKPaymentAuthorizationStatus instead in the Abletive-Swift.h when I tried to compile and run, apparently this is happening because of Objective-C compatibility right? Because there is no error whatsoever in the Swift code.
My project is currently half Objective-C and Swift.
Add this line to your BridgingHeader.h file
#import <PassKit/PassKit.h>
If you encounter more errors in "YourProjectName-Swift.h" find frameworks in which are classes that causes error and add imports in BridgingHeader.h like
#import <FrameworkInWhichIsClass/FrameworkInWhichIsClass.h>

Generic classes in "frameworkname"-Swift.h causes "Type name requires a specifier or qualifier" error in Xcode 6.3

I updated to Xcode 6.3, and I had two separate projects (one is a framework) in my workspace. Now, Xcode autogenerated this "frameworkname"-Swift.h header file, but when I had a generic class as a property, it produces the following lines:
#class Presentation;
SWIFT_CLASS("_TtC13BusinessLogic31MeetupDetailViewControllerModel")
#interface MeetupDetailViewControllerModel : NSObject
#property (nonatomic) /* RsvpStore<Rsvp> */ anRsvpStore;
#end
There is no equialent to gerenics in Objective-c, so how can I solve this problem?
I found that I can solve the problem if I set the type to NSObject like:
#property (nonatomic) NSObject * __nonnull anRsvpStore;
but with every build, this file is recreated to the same wrong version. So how can I force this build to set the type of this generic to NSObject?
I could stop creating this compatibility header by setting in Build Settings -> Swift Compiler - Code Generation -> Intall Objective-C Compatibility Header to No.
Since I've not written Objective-C code in my project, there is no problem with this option, but this is rather a workaround than a solution for generics in the compatibility header.
Another workaround is if you mark your properties with private, then they won't appear in the compatibility header.
Swift 2.0 update
A new
#nonobjc
attribute is introduced to selectively suppress ObjC export for instance members that would
otherwise be
#objc
. (16763754)
Blockquote
Not tested, but this looks like a solution.
I solved in #1873 https://github.com/realm/realm-cocoa/issues/1873
If you don't need to use swift in objc,just set Intall Objective-C Compatibility Header to No.
If you need to use swift in objc,you have to edited the -Swift.h and set it in Objective-C Generated Interface Header Name

How to enable the new Objective-C object literals on iOS?

When I create a new project with Xcode 4.4 and add these lines:
NSDictionary *test = #{ #"key" : #"test value" };
NSString *value = test[#"key"];
NSLog(#"value is: %#", value);
it compiles with no warnings and executes as expected.
Adding the same lines to an existing project produces the compiler error:
NSString *value = test[#"key"]; <-- Expected method to read dictionary element not found on object of type 'NSDictionary *'
I compared both projects' target build settings but nothing leapt out at me.
Update:
The new project that successfully compiled was for OSX. I tried another new one for iOS with the above lines and it fails to compile, same as my pre-existing (iOS) project.
This has nothing to do with old vs. new project, but rather is a factor of the SDK you use. The problem you're running into is that while this is a compiler feature, it requires SDK support. The iOS 5 SDK does not provide that support, though the iOS 6 SDK does.
For that reason, now you should just use the iOS 6 SDK. Read on if you want to use object subscripting with the iOS 5 SDK.
All you need to do is add a header file so that the compiler will try the call. There's no need to add an implementation; it's handled automatically by arclite. (If you are not using ARC, you will have to force the linker to include arclite. But you still don't have to actually switch to it.)
Create a new interface file, NSObject+subscripts.h.
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000
#interface NSDictionary(subscripts)
- (id)objectForKeyedSubscript:(id)key;
#end
#interface NSMutableDictionary(subscripts)
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;
#end
#interface NSArray(subscripts)
- (id)objectAtIndexedSubscript:(NSUInteger)idx;
#end
#interface NSMutableArray(subscripts)
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;
#end
#endif
I've put this chunk on github.
Note: I used to suggest adding the required methods to NSObject before explaining how to add them only to the relevant objects. In retrospect, I believe this was an error on my part; it led to errors being caught at runtime rather than compile time, unlike the approach now presented here. That approach is still on my blog, but I now believe it to be more of a cool hack than a useful approach.
Source:
Peter Steinberger, Using Subscripting With Xcode 4.4 and iOS 4.3+

Xcode and ZXingWidget: Importing Obj-C header files within .mm files

I use XCode 4.0 for developing an iOS project.
In my current project, I added the ZXingWidget library correctly but I had to change the .m extension in .mm in the class which implements MyViewController in order to import "QRCodeReader.h" and "ZXingWidgetController.h", the two headers I need to use the ZXing library.
Now, if in the same MyViewController.mm I want to also import my AppDelegate (which is obviously an Objective-C class), I receive a compile error which Xcode signals into other header files that are recursively added by my AppDelegate. These errors are of these kinds:
GCC 4.2 Error - Instance variable '<unnamed'> has unknown size
Expected ';' before 'public'
Expected unqualified-id before 'public'
I believe this is because I don't manage correctly the Objective-C and C++ mixing, and as I comment the line #import "MyAppDelegate.h" the error disappears.
Is there something I can do to fix this problem? Also a workaround could do!
Thanks!
Edit 1: The error does occur only if I import the App Delegate header in that .mm file. In every other .m file of my project I can successfully import the same App Delegate without errors. I feel there's something wrong with the .mm extension and GCC.
SOLVED: I had another external library interface which used this code
#interface Name : NSObject {
#private
#public
id var1;
int var2; // ecc...
}
And the error was pointing to the keyword #public. I commented the #private keyword and everything went just fine! I would be happy if someone could explain me the reason of this.