Parse class not created through swift code - swift

I am experiencing an issue when I try to create a new parse class through swift. My code for creating a new class is the following:
let query = PFQuery(className: "newClass")
The issue is that a "newClass" class is not created in my Parse dashboard and I don't get an error message. And since some other code is dependent on retrieving information from this class the app does not function properly.
I have created classes through swift previously and have never run into this problem. I also know that I can create a new class directly through Parse, but that doesn't really help me since there seems to be an issue with the connection between my swift code and Parse.
Thank you in advance for any help!

Is Allow client class creation turned on?
Try using PFObject to create the new class
PFObject(className: "yourNewClass")

I managed to solve it to some extent. After quite some while I got the idea to try to simulate the app on my iPhone instead of only on the simulator that xcode provides. For some reason everything then worked as planned... This is good news for me, but I would like to know why xcode couldn't do it.
Thanks for taking time and giving me some tips Brett!

Related

I get a warning in my console when load data from Coredata

i have a small problem with my code. When I load data from my CoreData I get warnings in my consol but I don´t know why. I´m not a professional programmer and also google couldn´t really help me so now I´m here.
I load my data like this:
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
var data: [DataToLoad] = []
override func viewDidLoad(){
do{
data = try context.fetch(DataToLoad.fetchRequest())
}catch{
print("error")
}}
But when I load it like that the console says...
"2020-09-05 20:32:04.884728+0200 Test-Application[3850:348569] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release"
...after I start the App.
So I mean everything is working fine, but where is my error that this massage appears.
I hope you can help me.
Sorry for my bad english I hope you can understand everything.
Have a nice day and thank you all.
The app is still working because it's a warning and not an error but it's good to not ignore warnings.
In your case, the warning occurs because NSKeyedUnarchiveFromData is deprecated. This means it's outdated and will be replaced in the future and the app might then stop working.
Kaira Diagne explains:
With iOS 12 Apple has started adopting NSSecureCoding across the entire platform. For Core Data this means that the default ValueTransformer, which uses NSCoding to transform a custom data type into a format that can be stored in the persistent store, at some point will change as well.
In your case NSSecureUnarchiveFromData instead of NSKeyedUnarchiveFromData in Core Data.
This means that the first thing we need to do is make sure that the data type of every transformable property in our data model conforms to secure coding.
(Link: NSSecureCoding and transformable properties in Core Data, 2020)
For your app to also work in the future you will have to dig somewhat deeper into the code and see where you are using the deprecated methods and classes and replace them.

Undefined symbol trying to link XCTest target

I am trying to test my application that uses Core Data. In order to test the my "save" method, I am using XCTNSNotificationExpectation for the notification NSManagedObjectContextDidSave, as shown below.
However, when I run it, I get the following errors.
I have other test files that test synchronous methods, which work perfectly if I comment this file, so I think the problem is with the notification or the expectation.
Could someone help me please?
Thank you!
The error states that it couldn't find the API NSManagedObjectContextDidSave which belongs to Core Data
You have to import the framework
import CoreData

trying to use coredata with an object class ** unsuccessfully**

I am completely lost trying to set up core data to be used inside my nsobject class. I am adding coredata to my existing project so its quite hard to figure this all out. Because of this I have started a new project with coredata to get the sample code I need to implement coredata in my current app.. however I am wondering what alterations do I need to make in order to use this coredata sample code with an object class instead of a view controller/tableview which is what the template code is doing?
To help answer my question I will explain what I am doing with my project at the moment.
I have several viewcontrollers that display different sets of data, because I have a custom database engine I am having to communicate with I have two classes that I have made. One is a request class which creates a packet with all sorts of data that gets sent off to the DBEngine using NSURLRequest/NSURLConnection.
I am using NSURLRequest/NSURLConnection delegates in my custom request class, so when send my request off to the DBEngine i wait until I get a response inside connectionDidFinishLoading delegate method, which I then pass the response data over to my responses class like so....
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// depending on what sorta request is made will depend on how the data shuld be handled.
if ([methodName isEqualToString:#"GetDBVersion"]) {
//tbc
}
else if ([methodName isEqualToString:#"GetManuf"])
{
[engineResponses GetManuf:receivedData];
}
else if ([methodName isEqualToString:#"GetNonM"])
{
[engineResponses GetNonM:receivedData RestrictionID:RestrictionID];
}
}
By doing this I am creating a new instance of my engineResponses class, which Is okay untill I try to pass the context from the application delegate over to this same class thus creating another instance which equals to things not working....
So as stated above I am wondering how I can edit the template code to work in my favor... I hope I have been clear in my explination I have just spent the last hour on trying to get this question perfect as I have spent the last two days chasing my tail trying to figure this stuff out.. its the first time I have worked with coredata and im just finding it hard to come to grips with it because I seem to be using it in an unconventional manner....
any help would be HUGELY appreciated.. if you need any more code example or better explanations please ask.. I will do anything I can to get help..
Okay So I found out the problem was with declaring multiple instances of the same object.. So all I had to do was use a singleton design patter to get it working perfectly.
Alot of people dislike singletons but I am not sure how else to get around this issue???? any suggestions would be greatly appreciated.
Also I know this worked because I have since checked the DB by logging the storeURL in the appdelegate, then copying pasting that dir, into the goto file - then opening up the sqlite db in xcode.. all the values are in there perfectly.

iphone coredata with two xcdatamodel

I've been working with core data (successfully ;) , following some tutorials and kind of getting all, but now I have a question about some basic tutorial I found some time ago (the author is not responding so here we go!)
this is the tutorial, and the code for it is here
in this tutorial, there are 2 xcdatamodels??, why? what is the timeStamp on the Event does?? I checked it in sqlitemanager, and after creating some data, timestamp doesnt save anything,
so was it a mistake to leave the Event entity? with its datamodel?
or is there something Im missing?
thank you!
It looks like CoreDataTutorialPart1.xcdatamodel (the model file containing the Event entity) was auto-generated by the Core Data Xcode template and isn't actually used anywhere in the project.

OCUnit will not allow me to use my own data types

I am using XCode 3.2.2 to unit test some custom data types. The tests run properly without those data types, but when I use said data types, I get this error:
"_OBJC_CLASS_$_classname", referenced from:
(where "classname" is the, well, class name...)
I have seen hints online that it could be linker related. The strange thing is, I originally followed these instructions http://www.mobileorchard.com/ocunit-integrated-unit-testing-in-xcode/ and they worked for me the first time I tried them. Now, after following the same instructions, I'm getting the same error. Any help would be greatly appreciated.
Thanks!
-Matt
Unfortunately your question is pretty ambiguous.
First, is the example working given in the mentioned tutorial?
Second, I'd double check your code:
Right click the class (.m) you're trying to use with OCUnit and click get info. Make sure the target in the class file is pointing to OCUnit! This is key for the linking.
Are you importing your .h for the associated class in the test case?
Check the spelling of the class names?