I'm trying enable the Parse Local Datastore. In the Parse Docs, they said to put the code enableLocalDatastore before setApplicationId:clientKey:, but this throws an exception:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'You have to call
setApplicationId:clientKey: on Parse to configure Parse.'
v1.6.0
Place the code for enableLocalDatastore after setting applicationId and clientKey. It looks like it was simply a mistake in their documentation.
v1.6.1+
Place the code for enableLocalDatastore before setting applicationId and clientKey.
Just be sure you don't have any cachePolicy set in your code.
In my case I had
query.cachePolicy = kPFCachePolicyNetworkElseCache
There is not need of a cache now you have your data in a local database.
I was having the same error.
I commented this line" // query.cachePolicy = PFCachePolicy.CacheElseNetwork" and it works.
override func queryForTable() -> PFQuery {
let query: PFQuery = PFQuery(className: self.parseClassName!)
if(objects?.count == 0){
//query.cachePolicy = PFCachePolicy.CacheElseNetwork
}
query.orderByAscending(Column Name")
return query
}
Related
I am creating a swift 3 parse live query messaging application. When a picture is sent, if the subscription gets the new message then i get the following error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI getDataInBackgroundWithBlock:]: unrecognized selector sent to instance 0x60000106e9c0'
When I reload the page and the original query gets the picture it works fine.
Here is my code
this is my original query that I subscribe to
var messagesQuery: PFQuery<Message> {
return (Message.query()?
.whereKey("roomName", equalTo: chatName)
.order(byAscending: "createdAt")) as! PFQuery<Message>
Here is my subscription to that query
func subscribeToUpdates() {
subscription = liveQueryClient
.subscribe(messagesQuery)
.handle(Event.created) { _, message in
self.messages.append(message)
DispatchQueue.main.async(execute: {
self.collectionView?.reloadData()
})
}
}
Here is the code causing the crash to occur (again only when the message is recieved via live query subscription rather than traditional query)
(message.image)?.getDataInBackground(block: { (data:Data?, error:Error?) in
if error == nil {
cell.messageImageView.image = UIImage(data: data!)
}
})
I have model like this:
class Session: Object {
dynamic var token: NSData?
}
class SessionsPool: Object {
let sessions = List<Session>()
}
I can request all sessions (normally there is one or zero) with required token
let myToken: NSData = ...
let sessions = self.realm.objects(Session).filter("token == %#", myToken)
It works well.
And I would like to request all pools that has at least one session with required token. And I would like to "observe" this request for updates.
let myToken: NSData = ...
var pools = self.realm.objects(SessionsPool).filter("ANY sessions.token == %#", myToken)
pools.addNotificationBlock { (change) in
// Some code
}
But I can't do it due to error:
*** Terminating app due to uncaught exception 'Unsupported operator',
reason: 'NSData properties cannot be queried over an object link.'
So I can use predicates like token == *someNSData* or like ANY sessions.stringToken == *someNSString*, but not like ANY sessions.token == *someNSData*.
What's wrong with NSData?
That particular query type hasn't been implemented yet: https://github.com/realm/realm-cocoa/issues/4222
However, your query can be refactored to something that Realm does support:
Replace this: ANY sessions.token == %#
With this: SUBQUERY(sessions, $session, $session.token == %#).#count > 0
I'm trying to convert a CNContact array to vCard using the method CNContactVCardSerialization.dataWithContacts(). But it is giving me the following error.
2016-07-25 14:05:00.115 AddressBook-ios9[902:28918] Exception writing contacts to vCard (data): A property was not requested when contact was fetched.
I made sure that I'm passing an valid array of CNContacts, but still it is giving this exception. Can anybody guide to me to what I've done wrong?
I'm attaching the source code below.
func getVcardFromSearchingName(name: String) -> NSData? {
do {
if let contacts = searchMultiContacts(name) {
print(contacts)
let vCard = try CNContactVCardSerialization.dataWithContacts(contacts)
return vCard
} else {
return nil
}
} catch {
return nil
}
}
I found out my mistake. On the keys to fetch contact, I was missing CNContactVCardSerialization.descriptorForRequiredKeys(). After adding it, the code is working flawlessly.
I am trying to catch an error when I execute a FetchRequest with a wrong/inexistent Key/Keypath but the app still crashes.
This is how I created the NSPredicate:
let pred = NSPredicate(format: "(\("WRONGKEY") = %#)", equalTo)
let request = NSFetchRequest()
request.predicate = pred
request.entity = MyEntityDescription
(WRONGKEY is a parameter that could be wrong/nonexistent in the Core Data schema)
And this is the line that cause the error:
var objects = managedContext?.executeFetchRequest(request, error: &error) as? [Model]
This is the error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath keyX not found in entity < NSSQLEntity EN id=2 >'
* First throw call stack: .....
So I have tried to use:
if let objects = managedContext?.executeFetchRequest(request, error: &error) as? [Model] {
println("okkkkkkkk")
} else {
println("error")
}
but doesn't work.
I have tried:
if(error != nil) {
but doesn't work either.
Is there a way to catch the error and avoid that the app crashes?
In Swift, try-catch isn't available. You can switch back to Objective-C, or use a library like this one to add the functionality.
That said, your problem can be solved by keeping track of which keys are valid, instead of implementing a try-and-see approach.
I am getting response from Twitter Response using FHSTwitterEngine.
Code Output
How can I get username and name key values. as I try this
self.screenName = [dicUser objectForKey:#"screen_name"];
It gives error.
[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0xcca78b0
You're assuming that the return value is an NSDictionary when in fact it is an NSArray. Protect yourself from crashing by wrapping your call with:
if ([dicUser isKindOfClass:[NSDictionary class]])
{
}