Getting started with MagicalRecord - core-data

I have an iPad app, using Storyboards, XCode 4.5 and iOS 6. I am trying to get started using MagicalRecord. I have everything installed and it builds correctly. I have created an empty entity called ClientInfo with attributes. I have also generated the NSManagedObject (Editor > Create NSManagedObject Subclass… > Create) but don't know what to do with it either.
This is the instruction that is my "brick wall"; I am unable to follow the following instruction:
import the NSManagedObject subclass of the entity you want to save
into you’re class
I have looked at examples, Googled it and looked at SO. I can't find a good example from starty to finish. Anybody know of a real good doc or example on MagicalRecord? Or, show me a real simple example that explains this where the MagicalRecord does not?

In Xcode, select the entities in the Core Data model editor and choose "Editor -> Create NSManagedObject Subclass ..." from the menu. This creates .h and .m for each entity, e.g. ClientInfo.h and ClientInfo.m.
Import the NSManagedObject subclass in your class file, e.g. #import "ClientInfo.h".
Note that you have to redo step 1 after modifiying the entities.
The NSManagedObject subclasses declare all the properties and methods for you entity, so you can (for example) write
clientInfo.name = #"foo";
instead of
[clientInfo setValue:#"foo" forKey:#"name"];

Related

Creating Xamarin ios storyboard interfaces using classes that are not directly or do not inheret directly from InterfaceController

When creating a WatchKit (WatchOS) Interface controller in the storyboard designer/editor, I cannot set it's class to something that is not itself type WKInterfaceController nor an immediate derived child of WKInterfaceController.
Basically in the hope of abstraction and better code reuse, better design overall, I would like to be able to use classes that are how to say, a more distant relative of their base WKInterfaceController
Basically right now it seems that your stuck using the storyboard designer to make a new WatchOS project. And using the storyboard designer you only have the option to select the WKInterfaceController class:
public partial class WKInterfaceController
or one that directly inherits from it:
public partial class ChildInterfaceController : WKInterfaceController
but nothing else such as:
public partial class GrandChildInterfaceController: ChildInterfaceController
So is there any way to do this that doesn't risk the chance of getting corrupted when you reenter the storyboard designer at some point?
Note: I've already asked if it is possible to avoid using a storyboard all together, but that has gone unanswered so I'm assuming no.
For clarity I'm talking about this dialog for "class":

Add readonly attributes (getters) to NSManagedObject

I have a ruby class and a match definition in core data.
There is a NSData field 'image_data' to store my image.
In my ruby class, i was thinking to add a getter to return an UIImage.
However, i get an error saying "undefined method `image' for #"
What do i need to do to get around this?
class ActivityImage < NSManagedObject
def image
UIImage.imageWithData(image_data)
end
end
I think what you're looking for is a way of creating a "Transformable Attribute".
If you read through that guide, you'll get to understand what transformable attributes are, hopefully you're using Xcode's model editor so you can just create the attribute in there, but otherwise you'll just have to pull some hackery to get the entity then create the image attribute and set it as transformable.

Adding UIWebView to second (not first) Storyboard view controller

Getting started with xCode 4.6.3 and I'm running into a hiccup.
I've built a simple app using the UIWebView to display a local HTML file and it's contents. I used that to debug any issues with the HTML and/or image displays and I'm all set.
Now I need to recreate that within a larger project I've built with storyboards for all my navigations between multiple view controllers. My issue comes when I'm trying to control-click drag from the WebView into the ViewController.h code below the #interface like many tutorials show, and that worked fine within my smaller single view controller app. It won't do it. I know I'm missing something obvious here. Am I going to have the set up these screens (I have multiple ones to do this same way) as separate xib files and add them into my main project?
Thanks for any help and clarification.
-Chris
You can create a class called for example myWebViewController and in Interface builder add a UIWebView to it. The control+drag to the header file will work.
Every time you want a UIViewController that has a browser in it, define its class as myWebViewController in Interface Builder.
Try not to repeat code. If you see UIViewControllers or any other UIView...that do the same thing, you can group them into a class that you use over and over.

MonoTouch 5 Error: "Failed to find selector setXxxxxx" after migrating to Xcode 4.2 and MonoDevelop 2.8

I have an iPad project that has been under development in Xcode 3.2.6 / MonoTouch 4.2.x / MonoDevelop 2.6 and when I installed the Monotouch 5, MonoDevelop 2.8.1 and Xcode 4.2 the project compiled and run OK. But when I started to change the XIB files in Xcode 4.2 (adding outlets) I started to have some glitches:
1) App crashes and MonoDevelop in debug mode says the the views were not loaded because the view outlet was not set. I figured out that in Xcode 4.2 there is no need to create an outlet named "view" in the .h file and just need to connect the File Owner view to the view control in the designer. Correct?
2) The main problem and is not solved yet is that I get exceptions "Failed to find selector setXxxxx" where "xxxxx" is a name of an outlet for a UI control. It started to happen in ViewControllers that inherited from a base view controller, but as soon as I started to change other normal viewControllers I get the same type of errors. Any hints of what is wrong?
3) I have a controller that loads dynamically some views and that works fine. but when I set a property on one of this sub views outlets (like the Text of a UILabel) the value is set (on the debugger) but no change in the UI. The actions for example work fine. What could be wrong.
4) Any special settings in the XIB's that are needed in order to correctly under Xcode 4.2 to integrate well with MonoDevelop 2.8?
Help is much appreciated, I thought in going back to the previous set of tools and monotouch but I guess once the project was upgraded there is no way to go back without losing all the development done now.
Thanks, Pedro
EDIT: Beside the new clean attributed [Outlet] code generated by MonoTouch 5 (replacing lot of code previously generated), the significant difference is that before the partial class generated was public and now is private, this may be the source of my problem. Is there a way to generate public partial classes or protected?
EDIT 2: If I manually add the public keyword to the partial class and members generated by MonoTouch in designer.cs the selectors are generated behind the scenes and all works. This indicates that with the change from public to private partial class the bindings generation changed in MonoTouch 5, is it by design or bug? I would find it very strange that now its not possible to create a viewcontroller with outlets, subclasss it and the child viewcontroller cannot access the parent class outlets.
1) There is indeed a view outlet on the base UIViewController class, which is an Objective-C property. When using Interface Builder 3 with MonoTouch, IB often didn't allow connecting to the base view outlet so many users created their own in their custom subclasses. MonoDevelop 2.6 and older created these custom outlets as ivars (Objective-C fields), and apparently the UIKit runtime would connect the object to both versions of the outlet - both the custom ivar and the base property. MonoDevelop 2.8 generates the custom outlets as properties, which means that the redundant view outlet shadows the base view outlet, so the base view outlet is never set, and UIKit gets unhappy. You can fix this by removing the redundant custom view outlet - MD 2.8.2 will do this automatically.
2) Seems to be a bug with the way MonoTouch exports custom outlets that prevents connecting to custom outlets defined in base classes. A possible workaround is mentioned on the bug report.
3) The UI rendering won't update while your app is paused in the debugger, it'll update on the next mainloop iteration.
4) Nope.
5) The class accessibility should be controlled by the user class part, not the designer class part, so you can freely change it.

Generate code for core data attributes in xcode 4

In xcode 3 there was a helpful feature in the data model builder where you could highlight some attributes/relationships in an entity, right-click, and choose to copy method and property declarations to the clipboard. (You could choose if you wanted objective-c 2.0 property declarations also). Then you could paste them into your NSManagedObject subclass.
I see how you can still generate the entire class file; but this isn't helpful if you are adding attributes to an existing entity. Have they removed this feature from xcode 4? I used it all the time!
See the Core Data Model Editor Help: Creating Objective-C Accessor Methods for a Managed Object
You may find MoGenerator useful.
Watch out for the fact that the special paste menu item only appears in the Edit menu not the contextual menu in the source editor.

Resources