I have an iPad app that I am porting from Windows C#. I created the entity and attributes (parital listing in image):
This is how I defined the attributes in the app:
This is the code to initialize MagicalRecord (v2.3) in AppDelegate.m file:
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:#"bim.sqlite"];
defaultContext = [NSManagedObjectContext MR_defaultContext];
I have this code in the DetailViewController.m file:
#import "AppDelegate.h"
#import "Books.h"
#class Books;
#interface DetailViewController : UIViewController <UITextFieldDelegate> {
}
This is the code causing the error:
- (IBAction)aAddRecordToCoreData:(UIButton *)sender {
Books *bks = [Books MR_createEntity];
bks.aAuthor = oAuthor.text;
bks.aBinding = oBinding.text;
bks.aBookDescription = oDescription.text;
This is the error I'm getting:
-[Books setAAuthor:]: unrecognized selector sent to instance
As far as I can tell, this is the same code I have used in another iPad app which is working correctly in the App Store. I doubt it has anything to do with MagicalRecord, but one never knows. What am I missing? or doing wrong?
Related
I'm new to objective-c, so please forgive me if the words are not precise.
I'm trying to transfer data between class files, my code:
in HomeViewController.h file:
#import <Cocoa/Cocoa.h>
#import "TimeInputFormatWrongPromptViewController.h"
#interface HomeViewController : NSViewController
#property NSTextField *wrongMessageBox;
#end
in HomeViewController.m file:
#import "HomeViewController.h"
#implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_wrongMessageBox = ((TimeInputFormatWrongPromptViewController*)NSApp.windows[0].contentViewController).wrongMessagesBox; //error here
}
#end
in TimeInputFormatWrongPromptViewController.h file:
#import <Cocoa/Cocoa.h>
#interface TimeInputFormatWrongPromptViewController : NSViewController
#property (weak) IBOutlet NSTextField *wrongMessagesBox;
#end
When I write the wrong code, the main window has nothing. When I removed the error code, the main window showed the controls I put in.
And when I write the error code, an error will be reported when the main window is displayed:
2022-10-25 19:46:34.947503+0800 xxxx[8622:607549] -[HomeViewController wrongMessagesBox]: unrecognized selector sent to instance 0x6000014b4000
2022-10-25 19:46:34.947847+0800 xxxx[8622:607549] Failed to set (contentViewController) user defined inspected property on (NSWindow): -[HomeViewController wrongMessagesBox]: unrecognized selector sent to instance 0x6000014b4000
Can anyone tell me how to fix it?
Thanks in advance
I'm trying to create an Obj-C, CoreBluetooth virtual peripheral app and get this warning.
//
// ViewController.h
// sim_backend_empty3
//
//
#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>
#interface ViewController : UIViewController <CBPeripheralManagerDelegate>
#property (nonatomic, strong) CBPeripheralManager *peripheralManager;
#end
//
// ViewController.m
// sim_backend_empty3
//
//
#import "ViewController.h"
#implementation ViewController >>>>>>>>>> WARNING >>>>>>>>>> Class 'ViewController' does not conform to protocol 'CBPeripheralManagerDelegate'
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)start_BLE_advertisements
{
[[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil];
}
#end
You need to implement the required CBPeripheralManagerDelegate protocol method:
peripheralManagerDidUpdateState:
as mentioned in the documentation here: https://developer.apple.com/documentation/corebluetooth/cbperipheralmanagerdelegate?language=objc
The protocol’s required one method, peripheralManagerDidUpdateState:, which Core Bluetooth calls whenever the peripheral manager’s state updates to indicate whether the peripheral manager is available.
You can check out an Objective-C example of how to setup CoreBluetooth using this repo:
https://github.com/LGBluetooth/LGBluetooth
Back when I still coded in ObjC, it was the library I used - and it was pretty great.
At the very least, it will give you some ideas on how you should be implementing the interfaces.
Here is a Swift implementation of what it sounds like you're trying to do (based on your other question asked a few days ago). Maybe you can backport it to ObjC (disclaimer: I'm the author).
https://github.com/RobotPajamas/SwiftyTeeth/blob/master/Sources/SwiftyTooth/SwiftyTooth.swift
Before I was using NSNotificationEvents, but as I know I should be using delegate because of 1:1 relations (it will be used only in one place in code).
Basically Im new to objective-C and swift (Im JavaScript guy) and the code that I created after a few hours of reading and checking - it just doesnt work, because self.delegate in not defined.
Im trying to delegate "an event" from objective-C code to swift code. NSNotificationEvents works like charm, but I want to make it with protocols / delegate.
I guess, I just missing how to exactly initialize the delegate protocol.
ProtocolDelegate.h
#import <Foundation/Foundation.h>
#protocol ProtocolDelegate <NSObject>
- (void) delegateMethod: (id)data;
#end
Event.h
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import "ProtocolDelegate.h"
#interface Event : NSObject <RCTBridgeModule, ProtocolDelegate>
#property(nonatomic, weak)id <ProtocolDelegate> delegate;
#end
Event.m
(someMethod is executed from JavaScript React-native code, but it shouldn't be any difference from what I know)
#import "Event.h"
#implementation Event
RCT_EXPORT_MODULE(Events);
RCT_EXPORT_METHOD(someMethod: (NSString*)parameter) {
NSDictionary* data = #{#"parameter": parameter};
NSLog(#"This I can see");
if ([self.delegate respondsToSelector:#selector(delegateMethod:)]) {
NSLog(#"This I can not see");
[self.delegate delegateMethod:data];
}
}
ViewController.swift
class ViewController: UIViewController, ProtocolDelegate {
// Xcode has automatically created this method
func delegateMethod(_ data: Any!) {
os_log("ON AUCTION");
}
}
I want delegateMethod inside ViewController to be executed.
Or maybe I get the whole idea wrong? Objective-C is a bit confising to me.
I am getting error:use of undeclared identifier
here is the code for view controller where I am accessing the object of model class mapMembersData
for (NSMutableDictionary *getMemberElements in arData)
{
mapMembersData *notModelObject = [mapMembersData sharedInstance];//showing error
[notModelObject assignMemberData:getMemberElements];
[memberArray addObject:notModelObject];
}
Here is the code of model class:
#import <CoreLocation/CoreLocation.h>
#import <Google-Maps-iOS-Utils/GMUMarkerClustering.h>
#interface mapMembersData : NSObject<GMUClusterItem>
#property(nonatomic,retain) NSString *chatToken;
#property(nonatomic,retain) NSString *address;
+ (mapMembersData *)sharedInstance;
- (mapMembersData *)assignMemberData:
#end
#import "mapMembersData.h"
#import "Constants.h"
#implementation mapMembersData
#synthesize chatToken,
address,
static mapMembersData *instance;
+(mapMembersData *)sharedInstance{
#synchronized(self)
{
instance = [[super alloc] init];
}
return instance;
}
- (mapMembersData *)assignMemberData:(NSMutableDictionary*)getMemberElements
{
chatToken = [objdelegate checkIfStringIsEmpty:[getMemberElements
objectForKey:#"chatToken"]];
address = [objdelegate checkIfStringIsEmpty:[getMemberElements
objectForKey:#"address"]];
return self;
}
#end
What am I doing wrong?
In your storyboard there must be a controller, in which you had set a class with storyboard id, and you removed that class from that storyboard but the storyboard id is still addressing it, like below image:
So you have to remove that Storyboard ID and uncheck that "Use Story Board ID".
That's all.
After scratching my head for a day. I manage to get ride off the bizarre errors.
Finding starts from below:
1.mapMembersData-class were residing in two different folders of the workspace (In XYZ-folder and one at outside the folder). mapMembersData- the class was referenced by project i.e inside XYZ and other was just placed.
the controller from where I was accessing the mapMembersData, was at outside XYZ-folder, thus creating ambiguity.
I deleted unused referenced classed and confirm controller should access correctly.
In this part of my code I get a warning message saying it doesn't implement the custom protocol I made.
detailViewController.delegate = self;
How do I implement the protocol?
Then when I run the program it crashes saying
'-[DetailViewController setDelegate:]: unrecognized selector sent to instance 0x6a1c450'
Declare your class like this:
#interface DetailViewController : UIViewController <MyProtocol> {
// Class stuff
}