how to udate window controls(NSTextField,NSCheckbox and etc) in binding manually - objective-c

I am working on an application in which i need to store all the NSObject subclass properties into plist file and then allow users to store it and restore it. We call it profile and it can restore the saved state of all the controls/views on the window in my application.
I have completed the storing/Restoring part, but the issue is when i am updating the class properties manually, it is not updating the control state Like checkboxs and others which is bind with the class property.
Please let me know how can i update the controls state, if its KVC/KVO updated programatically.
Thanks in advance

You need to read this guide here
In particular read the section on "Automatic Versus Manual Support" which details how you need to change your properties so that you are KVO compliant.

Related

Xcode 7+ Is there a way to Preserve App State after Recompiling

My application has deep navigational chains of 8+ screens deep (Wizard-style). When i'm editing a View Controller, and i want to make a quick visual change and re-test, As a tester, I have to go through the full flow to end up where I was before recompiling, in the same Data state. Is there a way that Xcode can somehow preserve the application state, and re-run the same view controller?
If there was an automated way to detect the last launched screen, and re-display it after the recompile, that would save a lot of developers a lot of time.
I realize something like this can be built custom. Something like:
IF A Certain Debug Flag is ON:
- Retrieve from NSUserDefaults the Class Name of the last controller used, and redisplay it.
The problem with this is: Data State and Navigation State will not be preserved. Also, all other object state which invokes and depends on your controller will not be included. That's why I need a more universal solution.
IF A Certain Debug Flag is ON: - Retrieve from NSUserDefaults the Class Name of the last controller used, and redisplay it.
The problem with this is: Data State and Navigation State will not be preserved.
But this is exactly the problem that the built-in state saving and restoration mechanism is intended to solve, is it not?
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html
I recommend you use a User Interface target and then create an XCTestCase that works on your view controller and exercise it. Use the new record button in Xcode 7 to get you started with the test case. Familiarize yourself with some of the new queries it uses for some of the dynamic information you may be creating.
Another option would be to inject your test case's UI state into the application delegate in the setup function of an XCTestCase. Then it will need custom logic to navigate to the correct view controller. Then your test case could focus on just that ViewController once the Application delegate has navigated to it.
Of course you can use the debugger and breakpoints in the Test Case and your View Controller while UI Testing. By "scripting" this you do significantly less manual clicking on a device to test a ViewCOntroller
Also you've now got a Test! Hopefully worth something to you down the road when you change something

User Control which triggers GeneXus events in iOS

I'm developing an iOS User Control for Genexus X Ev3, is based on Maps an inherits from GXControlGridBase, the main function is to select a point in the map and return the geolocation updating Genexus attribute and launching an event showing a message with the coordinates stored in the attribute.
Searching I found this:
1- in control definition, .control file defines an event
<Events>
<Event>EventName</Event>
</Events>
2- in Genexus code
Event Control.EventName
...
EndEvent
3- To trigger from Objective-C
[self fireControlEvent:#"EventName" userInterfaceContext:nil withEntityData:nil];
Steps 1&2 are ready (and they work, there is a UC version for Android).
In case of Objective-C ¿where I can put that line? ¿how update the genexus attribute value?
Thanks in advance.
To select a point in a map, you can use the SD Geolocation user control that is built-in in GeneXus.
If you, however, want to make your own user control, you'll probably want to make it a subclass of GXControlEditableWithLabelBase or GXControlEditableWithLabelSingleEditorViewBase. That is, given that you want it to have an associated attribute. You say you are using a GXControlGridBase subclass, that is for lists of values, not just an attribute.
As for the last part of your question, if you need to update the attribute's value, there is no need to trigger an event. You can call this method from the control's implementation:
[self updateEntityDataResolvedFieldWithValue:fieldValue];
The method -updateEntityDataResolvedFieldWithValue: is defined in the GXControlEditableWithLabelBase base class.

Saving and restoring different subset of settings while using cocoa bindings

I have an app where the user should be able to create template settings files, to save and choose from a popup list. These settings will be applied to configure an export of an item.
I just don't know how to best approach the problem of saving and restoring the saved settings.
To add to my problem is the fact that there are many different exporting methods, each with different setting types.
To explain:
User configures the settings they want for export method A, he/she saves these settings and here i want to write them to disk in a plist file.
The the user configures another set of settings for export method B, he/she saves these settings and i want to write these to disk aswell.
I have used NSSharedUsersDefaultsController to bind all interface elements and test bindings, but i don't want to keep all settings in the application plist. Also, I don't know if there is a good way of importing/exporting using that technique when i'm using different subset of settings. If there was a good way of binding to sub-dictionaries then that could work, but I have not been able to make that work.
I could create a Class for each export method and bind the settings to an NSObjectController, and then manually create an import and export method but that felt clunky.
NSDictionaryController and NSArrayController only seem to be made for TableViews and that kind of data display, not single user interface elements, at least from what i've been able to test.
So, is there a good way to create an export/import functionality while still using cocoa bindings, or do i have to create my own methods for that?
Any examples or pointers in the right direction is appreciated.
A simple and suggest way of saving not critical / not secure settings is:
[NSUserDefaults standardUserDefaults]
You can access it like a dictionary with getObject: and setObject:

Objective c - Core Data saving approach

I have some NSManagedObject subclass in my app, and I'm trying to understand when and how to save changes.
I will try to explain myself, for example class A is NSManagedObject subclass.
During app life cycle I do:
App launched
...
Create an instance of class A
...
Change some properties of A instance
...
App go to background
...
App becomes active again
...
Change some more properties of A instance
...
App terminates
When do I need to call [context save:] ??
Do I call it after every change in A instance? Or maybe I call it only when app go to background?
Should I call it after creation or deletion of any A instance?
A nice approach is place UIManagedDocument in your AppDelegate. Then you can call [context save] whenever some change occurs in the app (like a crash). The order I like to follow is something like:
Create UIManagedDocument object (in application did load or wherever)
and assign it to a property
Setup the document (check whether it exist on disk or is already open, etc.. and respond accordingly)
Pass the UIManagedObjectContext to the initial UIViewController in your app (from there you can pass the context to other view controllers)
UIManaged document will save the context for you.
Take a look at the UIManagedDocument documentation to configure persistent store options (you send an NSDictionary of options to your UIManagedDocument instance, see the first example through the link below).
UIManagedDocument documentation:
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIManagedDocument_Class/Reference/Reference.html
Also see the CoreData lecture and demo (lectures 13 and 14) of the iPhone and iPad application development course with Paul Hegarty available free on iTunesU (Fall 2011).
The data will not be saved to the persistent store until you call save. So, it depends on what you want in your app. If you want it to be able to recover the last value it ever had, then you should save after each modification.
Easy change is to just save after making modifications.
You could do something a bit more fancy, like only save after some set amount of time, so many changes are grouped together... and catch any event that will put your app in the background and then save...
But, that's what UIManagedDocument does automatically for you, so you could just use that instead.
Depending on the amount of changes that you make and the volume of data that needs to be saved with each change, yo can choose to save a little or a lot. If you are just saving a string or a number or a bool, then go ahead and call save: on your context as soon as the changes were made.
If it is a lot of data, you may want to coalasce your changes and then save it on a background queue so that you are not blocking the main queue. This way you are not waiting to go to the background to perform your saves.
Tim

Retain object through UIAlertView/UIActionView dialogs

I'm working on a local (to the method) custom object and need to display a dialog (UIActionSheet or UIAlertView) to the user. What's the best way to get access to same object when delegate is called after user interacts with the dialog? Any Cocoa tricks besides adding another instance variable to current class?
One way is to use "Associated Objects". (but you can't test it in simulator.)