Load data into NSData for processing in NSStoryboard

This commit is contained in:
Gregory John Casamento 2020-06-19 07:45:10 -04:00
parent 04d131fb44
commit 70a3baa428
3 changed files with 35 additions and 4 deletions

View file

@ -41,7 +41,10 @@ typedef NSString *NSStoryboardSceneIdentifier;
DEFINE_BLOCK_TYPE(NSStoryboardControllerCreator, NSCoder*, id);
@interface NSStoryboard : NSObject
{
NSData *_storyboardData;
}
+ (NSStoryboard *) mainStoryboard; // 10.13
+ (instancetype) storyboardWithName: (NSStoryboardName)name

View file

@ -91,7 +91,8 @@ NSApplicationMain(int argc, const char **argv)
mainModelFile = [infoDict objectForKey: @"NSMainStoryboardFile"];
if (mainModelFile != nil && [mainModelFile isEqual: @""] == NO)
{
if ([NSBundle loadNibNamed: mainModelFile owner: NSApp] == NO)
if ([NSStoryboard storyboardWithName: mainModelFile
bundle: [NSBundle mainBundle]] == nil)
{
NSLog (_(@"Cannot load the main storyboard file '%@'"), mainModelFile);
}

View file

@ -22,12 +22,31 @@
Boston, MA 02110 USA.
*/
#import <AppKit/NSStoryboard.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSString.h>
#import <Foundation/NSData.h>
#import "AppKit/NSStoryboard.h"
static NSStoryboard *mainStoryboard = nil;
@implementation NSStoryboard
// Private instance methods...
- (id) initWithName: (NSStoryboardName)name
bundle: (NSBundle *)bundle
{
self = [super init];
if (self != nil)
{
NSString *path = [bundle pathForResource: name
ofType: @"storyboard"];
_storyboardData = [[NSData alloc] initWithContentsOfFile: path];
}
return self;
}
// Class methods...
+ (NSStoryboard *) mainStoryboard // 10.13
{
return mainStoryboard;
@ -36,7 +55,15 @@ static NSStoryboard *mainStoryboard = nil;
+ (instancetype) storyboardWithName: (NSStoryboardName)name
bundle: (NSBundle *)bundle
{
return nil;
return AUTORELEASE([[NSStoryboard alloc] initWithName: name
bundle: bundle]);
}
// Instance methods...
- (void) dealloc
{
RELEASE(_storyboardData);
[super dealloc];
}
- (id) instantiateInitialController