Can we check the NSNotification table? - objective-c

For example, say I want to see what's the actual current table of NSNotification. I want to see how it change after I add notification, after I remove observers, etc.

Nope, you can't, at least without some runtime voodoo.

Related

EventFiringWebDriver / WebDriverEventListener invocation order

I'm implementing an EventFiringWebDriver, respectively, a WebDriverEventListener, where I need data both from before and after particular events (e.g. beforeClickOn and afterClickOn). Since I wasn't able to find anything in the docs, I would like to know if a situtation can occur where a before event isn't immediately followed by its corresponding after event? Something like:
(beforeEventA, beforeEventB, afterEventA, ...)
So, can I rely on the invocation order of before and after?
As you are implementing WebDriverEventListeners interface this surely can happen based on how you define the implementing methods.
Let me give you an example, say you are performing a click event and in beforeClickOn method you tried to perform an operation such as refesh page, so the behaviour will go like this:
beforeOnClick->beforeRefresh->afterRefresh->afterOnClick
As now you can see that the behaviour is totally dependent on how you want your driver to perform the task.
Hope this helped.

RESTful implementation for "archiving" an entry

Say I have a table for machines, and one of the columns is called status. This can be either active, inactive, or discarded. A discarded machine is no longer useful and it only used for transaction purposes.
Assume now I want to discard a machine. Since this is an entry update, RESTfully, this would be a PUT request to /machines/:id. However, since this is a very special kind of an update, there could be other operations that would occur as well (for instance, remove any assigned users and what not).
So should this be more like a POST to /machines/:id/discard?
From a strict REST perspective, have you considered implementing a PATCH? In this manner, you can have it update just that status field and then also tie it in to updating everything else that is necessary?
References:
https://www.mnot.net/blog/2012/09/05/patch
http://jasonsirota.com/rest-partial-updates-use-post-put-or-patch
I think the most generic way would be to POST a Machine object with { status: 'discarded' } to /machines/:id/.
Personally, I'd prefer the /machines/:id/discard approach, though. It might not be exactly in accordance with the spec, but it's more clear and easier to filter. For example, some users might be allowed to update a machine but not "archive" it.
Personally I think post should be used when the resource Id is either unknown or not relevant to the update being made.
This would make put the method I would use especially since you have other status types that will also need to be updated
path
/machines/id
Message body
{"status":"discarded"}

Getting user's location once, and only once

My app needs to know the rough location of a user, with a resolution of their state/province. This way we know what the default tax rate should be in a simple tax calculator. They can still pick it after that, but its always nice to try to get it right.
Is there an easy way to get this sort of resolution without all the rigamarole of callbacks and such? I don't need updates, a single rough location will do, and an old one is likely perfectly fine.
There are no short simple ways to get current location.
That means that you need init CLLocationManager object, call startUpdatingLocation method and retrieve result in delegate method.
It's impossible to get current location synchronously by using one line of code because retrieving location info could take much time (For example turning on GPS sensor and so on.). That's why you get info by asynchronous delegate methods.
is the only way,
but to get a single user position
within the method locationManager:didUpdateLocations: call stopUpdateLocation:
[locationManager stopUpdatingLocation]

nsfetchrequestcontroller.request

Is it okay to change that thing if we are not using the cache anyway?
To repeat, we're not supposed to change the fetchrequestcontroller request only if we do not use the cache right?
If I am displaying a table based on user search and the search change, should I create a whole new fetchrequestcontroller?
The documentation states "You must not reuse the same fetched results controller for multiple queries unless you set the cacheName to nil". It also states you should delete the cache if modifying the fetch request. I often use two different caches depending on the application. You can read more about NSFetchedResultsController here and it's delegate here.

How to set modification date every time NSManagedObject changes?

Every time one of my managed objects is modified, I want to store the date it was modified (in an attribute which is already in my data model), for convenience when I'm syncing with other clients.
Is there a way to do this without A) re-writing all my setters manually or B) relying on myself to always change the modification date every single time the object is modified?
You could register with the notification center to observe the NSManagedObjectContextObjectsDidChange notification.
This will tell you what objects are changed. You can check to see if your object is among them and take action accordingly.
Just for completeness, you can also do this in -willSave if you already have a subclass of NSManagedObject.