0

The console is filled with:

ViewBridge to RemoteViewService Terminated: Error Domain=com.apple.ViewBridge Code=18 "(null)" UserInfo={com.apple.ViewBridge.error.hint=this process disconnected remote view controller -- benign unless unexpected, com.apple.ViewBridge.error.description=NSViewBridgeErrorCanceled}

I've got the following source code files:

//
//  AppDelegate.h
//  ControllerBindings
//

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>


@end

//
//  AppDelegate.m
//  ControllerBindings
//

#import "AppDelegate.h"

@interface AppDelegate ()


@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
}


- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}


- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app {
    return YES;
}


@end

//
//  main.m
//  ControllerBindings
//

#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // Setup code that might create autoreleased objects goes here.
    }
    return NSApplicationMain(argc, argv);
}
//
//  Note.h
//  ControllerBindings
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface Note : NSObject

@property (strong, nonatomic) NSString * title;
@property (strong, nonatomic) NSAttributedString * text;
@property (strong) NSDate* created;
@property (strong) NSDate* edited;

@end

NS_ASSUME_NONNULL_END
//
//  Note.m
//  ControllerBindings
//

#import "Note.h"

@implementation Note
- (id) init
{
    self = [super init];
    if (self)
    {
        self.title = @"New note";
        self.created = [NSDate date];
        self.text = [NSAttributedString new];
    }
    
    return self;
}

- (void) setTitle: (NSString *) title
{
    self->_title = title;
    self.edited = [NSDate date];
}

- (void) setText: (NSAttributedString *) text
{
    self->_text = text;
    self.edited = [NSDate date];
}


@end
//
//  ViewController.h
//  ControllerBindings
//

#import <Cocoa/Cocoa.h>

@interface ViewController : NSViewController

@property (strong) NSMutableArray* notes;

@end
//
//  ViewController.m
//  ControllerBindings
//

#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.notes = [NSMutableArray array];
}


- (void)setRepresentedObject:(id)representedObject {
    [super setRepresentedObject:representedObject];

    // Update the view, if already loaded.
}


@end

I have no idea what am I doing wrong here. The binding setup seems to work but I have no idea why am I getting this error. To be precise this happens once I add a new note in the app and focus in the note text edit control.

I have the following storyboard setup:

  1. Open the interface and drag in the array controller. Open MainWindow.xib. We’re going to start by adding the NSArrayController instance, which lives in the Object Library. Search for array controller, and you’ll find it. Drag one into the outline.
  2. Bind the array controller to the app delegate(In my case it is in the ViewController). We’ll now instruct the array controller to access the notes property when it wants to know where the data it’s managing is stored. Select the array controller, and open the Bindings inspector. Open the Content Array property, and bind it to the App Delegate. Set the model key path to notes.
  3. Set the array controller’s class. We also need to let the array controller know about what class of object the array will contain. This is important because when the array controller is asked to add a new item to the array, it needs to know which class to instantiate. With the array controller selected, open the Attributes Inspector. Set the Class Name to Note.
  4. Add a table view. Drag in a table view and place it on the lefthand side of the window. Resize it so that it’s about a third of the width of the window. When you add a table view, it’s placed inside a scroll view. We’re going to want to set up several different aspects of the table view, so expand the entire tree by holding down the Option key and clicking the arrow next to Scroll View — Table View in the outline. Select Table View in the items that appear. Set the Columns counter in the Attributes inspector to 1.
  5. Bind the table column to the array controller. We want the table view controller to display note titles in the list. Select the Table Column in the outline and open the Bindings inspector. Bind the Value property to the array controller. Set the controller key to arrangedObjects and the model key path to title. The table view will now show the value of the title property for all items in the notes array. Additionally, the table view will control which item is selected.
  6. Add the add and remove buttons. We’ll now add two buttons to the view to allow adding and removing items. Drag in a gradient button from the object library. Resize it to a smallish square shape, and place it underneath the table view. In the Attributes inspector, set the button’s title to nothing (that is, delete all the text). Set the image to NSAddTemplate, which will make the button show a plus icon. Hold down the Option key and drag the button to the right. A copy will be made; place it next to the first button. Set the image of this new button to NSRemoveTemplate, which shows a minus icon.
  7. Connect the add and remove buttons to the array controller. We can now make these buttons instruct the array controller to add and remove items. Control-drag from the add button to the array controller. Choose add: from the menu that appears. Control-drag from the remove button to the array controller. Choose remove: from the menu that appears. Now when these buttons are clicked, the array controller will add a new item to the array that it’s managing or delete the currently selected item.
  8. Bind the remove button’s Enabled property to the array controller. For a finishing touch, we’re going to disable the remove button if there’s nothing to remove or if there’s no selected object. The array controller exposes a property called canRemove, to which we can bind the button’s Enabled property. Select the remove button and open the Bindings inspector. Bind the Enabled property to the array controller, using the controller key can Remove.
  9. Create the interface. Add a text field to the right side of the window and place it at the top. This text field will show the title property in the notes. Add a text view underneath the text field. Make it rather tall to allow for plenty of room for adding text. This text view will show the text property.
  10. Bind the controls. Select the text field and bind its value to the array controller. Set the controller key to selection and the model key path to title. Turn Continuously Updates Value on. Select the text view (note that it’s kept inside a scroll view, so you’ll need to expand it in the outline to get to it), and bind its value to the array controller. Set the controller key to selection and the model key path to text. Turn Continuously Updates Value on here, too.
  11. Create the date labels. Finally, we’ll create the interface that shows the date and bind it. Add a label to the window. Set its text to Created: and place it under the text view. Add another label and set its text to Edited:. Place it under the Created label. Add a third label and put it to the right of the Created label. Resize it to the right edge of the window. This label will display the date that the note was created on. Add a fourth label to the right of the Edited label. Resize it like the last one.
  12. Bind the date labels. Select the empty label to the right of the Created label and bind it to the array controller. Set the controller key to selection and the model key path to created. Select the other label and bind it similarly, but with the model key path set to edited. We’re done. You can now see the entire app in action! You can add and remove items, and store any text you like in the text field. Renaming the note updates live in the list, and changing the note’s contents updates the Edited label.

Buttfield-Addison, Paris; Manning, Jonathon; Nugent, Tim. Learning Cocoa with Objective-C: Developing for the Mac and iOS App Stores (p. 247). (Function). Kindle Edition.

The app window looks like:

App Window

6
  • 2
    "Benign". Did you notice that word? Commented Sep 25 at 17:57
  • Do you want to say that it is not an error? Commented Sep 25 at 18:10
  • I don't claim to know what it is. But I know what I would do. I would ignore it. Commented Sep 25 at 18:11
  • BTW, just to respond to the deleted AI slop: NSTextView does not and will not layout or render in an outside process. 🤦‍♂️ Commented Sep 26 at 13:08
  • 1
    Where did you see AI here? What are you talking about? It’s a regular cocoa macOS app. Commented Sep 26 at 15:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.