gpt4 book ai didi

ios - CoreData 设置关系给出错误'-[WeatherObservation count] : unrecognized selector sent to instance

转载 作者:可可西里 更新时间:2023-11-01 03:37:46 25 4
gpt4 key购买 nike

WeatherObservation 是我的数据模型中的一个实体,我试图设置它与另一个对象的关系(一对一),我通过导航 Controller 传入该对象。几周前它起作用了。我更改了模型中的一些其他实体,重新生成了类,并且此关系设置为 NSManagedObject,而不是其他实体的类。我尝试重新生成此类几次,然后将其更改为应有的内容并将该类添加到 .h,#import 到 .m

我假设 [MANAGEDOBJECT count] 消息是核心数据魔术的一部分,我不会在我的代码中的任何地方调用它。我不确定从哪里开始,该做什么,我可以在这里发布什么来帮助获得答案?我试过:

weather.hiveObservation = hiveObs;

还有

[weather setValue:hiveObs forKey:@"hiveObservation"]

两者都抛出相同的错误,如果我注释掉设置对象保存到持久存储的关系。 hiveObs 是在旧 View 中创建的,但尚未保存...是否重要?

编辑:经过深思熟虑并添加信息。
我传入的 ManagedObject 已创建,但在更改 View 之前未保存。它在新 View 中记录了 nil 值,但这可能是问题所在吗?

核心数据文件
HiveObservation.h

import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class BoxObservation, HiveDetails, WeatherObservation;

@interface HiveObservation : NSManagedObject
... //other properties omitted
@property (nonatomic, retain) HiveDetails *hiveDetail;
@property (nonatomic, retain) WeatherObservation *weatherObservation;
@end

@interface HiveObservation (CoreDataGeneratedAccessors)

- (void)addBoxObservationsObject:(BoxObservation *)value;
- (void)removeBoxObservationsObject:(BoxObservation *)value;
- (void)addBoxObservations:(NSSet *)values;
- (void)removeBoxObservations:(NSSet *)values;

@end

WeatherObservation.h

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class HiveObservation;

@interface WeatherObservation : NSManagedObject
//... other properties omitted
@property (nonatomic, retain) NSNumber * windSpeed;
@property (nonatomic, retain) HiveObservation *hiveObservation;

@end

控制台输出:

2015-01-21 14:28:32.739 Hive Maps[5085:69277] -[WeatherObservation count]: unrecognized selector sent to instance 0x78ea3140
2015-01-21 14:28:32.743 Hive Maps[5085:69277] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WeatherObservation count]: unrecognized selector sent to instance 0x78ea3140'
*** First throw call stack:
(
0 CoreFoundation 0x0157b946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01204a97 objc_exception_throw + 44
2 CoreFoundation 0x015835c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x014cc3e7 ___forwarding___ + 1047
4 CoreFoundation 0x014cbfae _CF_forwarding_prep_0 + 14
5 CoreData 0x00b2a8cc -[NSSQLCore _knownOrderKeyForObject:from:inverseToMany:] + 204
6 CoreData 0x00b2ae53 -[NSSQLCore _populateRow:fromObject:timestamp:inserted:] + 1043
7 CoreData 0x00a52e73 -[NSSQLCore prepareForSave:] + 1091
8 CoreData 0x00a52174 -[NSSQLCore saveChanges:] + 340
9 CoreData 0x00a1bfee -[NSSQLCore executeRequest:withContext:error:] + 638
10 CoreData 0x00b15af4 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 5380
11 CoreData 0x00b1ee9c gutsOfBlockToNSPersistentStoreCoordinatorPerform + 188
12 libdispatch.dylib 0x02d00e2f _dispatch_client_callout + 14
13 libdispatch.dylib 0x02ce5505 _dispatch_barrier_sync_f_invoke + 144
14 libdispatch.dylib 0x02ce4c37 dispatch_barrier_sync_f + 105
15 CoreData 0x00b0f7e7 _perform + 183
16 CoreData 0x00a1bb1b -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 459
17 CoreData 0x00a4b1d9 -[NSManagedObjectContext save:] + 1529
18 Hive Maps 0x00018a6d -[GetWeatherTableViewController saveWeatherData:] + 3133
19 libobjc.A.dylib 0x0121a7cd -[NSObject performSelector:withObject:withObject:] + 84
20 UIKit 0x0193023d -[UIApplication sendAction:to:from:forEvent:] + 99
21 UIKit 0x01ca0840 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 139
22 libobjc.A.dylib 0x0121a7cd -[NSObject performSelector:withObject:withObject:] + 84
23 UIKit 0x0193023d -[UIApplication sendAction:to:from:forEvent:] + 99
24 UIKit 0x019301cf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
25 UIKit 0x01a63e86 -[UIControl sendAction:to:forEvent:] + 69
26 UIKit 0x01a642a3 -[UIControl _sendActionsForEvents:withEvent:] + 598
27 UIKit 0x01a6350d -[UIControl touchesEnded:withEvent:] + 660
28 UIKit 0x0198060a -[UIWindow _sendTouchesForEvent:] + 874
29 UIKit 0x019810e5 -[UIWindow sendEvent:] + 791
30 UIKit 0x01946549 -[UIApplication sendEvent:] + 242
31 UIKit 0x0195637e _UIApplicationHandleEventFromQueueEvent + 20690
32 UIKit 0x0192ab19 _UIApplicationHandleEventQueue + 2206
33 CoreFoundation 0x0149f1df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
34 CoreFoundation 0x01494ced __CFRunLoopDoSources0 + 253
35 CoreFoundation 0x01494248 __CFRunLoopRun + 952
36 CoreFoundation 0x01493bcb CFRunLoopRunSpecific + 443
37 CoreFoundation 0x014939fb CFRunLoopRunInMode + 123
38 GraphicsServices 0x04d0124f GSEventRunModal + 192
39 GraphicsServices 0x04d0108c GSEventRun + 104
40 UIKit 0x0192e8b6 UIApplicationMain + 1526
41 Hive Maps 0x0001967d main + 141
42 libdyld.dylib 0x02d2cac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我做了一个堆栈跟踪,输入了一个异常点,当我保存时异常发生:

weather.hiveObservation = hiveObs;       
NSError *error = nil;
if (![_managedObjectContext save:&error]) {
//Handle the error.
NSLog(@"SAVE ERROR: %@",error);
}

Screen shot, can post the image directly

最佳答案

遇到了同样的问题。即使在清理和重建之后也会发生错误。仔细检查了关系,确实是一对一,但我仍然有同样的错误。

解决方案:删除“hiveObservation”关系及其在相应实体(如果存在)中的对应关系,并添加具有相同名称的新关系。

关于ios - CoreData 设置关系给出错误'-[WeatherObservation count] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28077521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com