Framework integration

I have controls and controllers that I have to include in my projects, over and over

So I wants to make a frameworkwith these controls library.


I have to precise that my framework has to includeAlamofire


I made the framework, but when I integrate it in a project and I subclass one of my windowControllers, I have the followin error inthe subclassed initializer: "Must call a designated initializer of the superclass 'clistWindow' "

Of course, I call the superclass initializer(which is in the framework) .


I tried in the subclassed initializer to call "super.init(window: nil)" but I have the error: "Argument labels '(window:)' do not match any available overloads"


I don't understand because in the framework class, I have an initializerwith initialise (to nil) all the variables. IL thought it was suficient to make a designated initializer.


On other thing: when I inspect the interface header of the class (I mean the .h file) I don't have this designated initializer.


Any Help?

Don't you need to indicate the framwork name when you reference objects of the framework ?


Try to specify the module in the subclass definition (in IB)

See here : h ttps://stackoverflow.com/questions/32622278/how-to-set-an-uiview-subclass-from-a-framework-as-a-storyboard-custom-class


May also have a look here about the initializers:

h ttps://stackoverflow.com/questions/24220638/subclassing-nswindowcontroller-in-swift-and-initwindownibname

"'I forgot to say it is an macOS development, not a IOS


In my frame work I have the class:


open class clistWindow: cbaseController{

public override init () {

super.init()

}

public override init(window: NSWindow!) {

super.init(window: nil)

}

required public init?(coder: NSCoder) {

super.init(coder:coder)

}

........

}


and in the main code:


class motsWindow: clistWindow {

var lstMots: [String]!

@IBOutlet weak var tableMots: cmyTable!

@IBOutlet weak var filtretypemmot: cmyCombo!

init() {

super.init()

chargements(0)

}

required init?(coder: NSCoder) {

super.init(coder: coder)

}

.....

}


in the initialize of motsWindow, I have the error: "Must call a designated initializer of the superclass 'clistWindow'"

So, the error:

"Must call a designated initializer of the superclass 'clistWindow'"


is in this init ? :

    init()  {
        super.init()
        chargements(0)
    }


NSWindowController have no init().

How is it defined for cbaseController ?


The doc states :

You should create a subclass of

NSWindowController
when you want to augment the default behavior, such as to give the window a custom title or to perform some setup tasks before the window is loaded. In your class’s initialization method, be sure to invoke on
super
either one of the
initWithWindowNibName:...
initializers or the
init(window:)
initializer. The initializer you choose depends on whether the window object originates in a nib file or is programmatically created.



Did you try to add the init(window: NSWindow!) in motsWindow

override init(window: NSWindow!) {
        super.init(window: nil)
    }



Note: your class names should start with Uppercase.

You said my class names should start with Upercase/ Is it an advice or is it mandatory? Because it works (when it is not in a frame work) perfectly well?


I trie to add the init(window: NSWindow!) in motsWindow, but I have 2 errors on this new initializer:

on the override init(window: NSWindow!) lilne I get "Initializer does not override a designated initializer from its superclass"


and on super.init(window: window) I get "Argument labels '(window:)' do not match any available overloads"


of course, the init(window: NSWindow!) in clistWindow is OK

The UpperCase is not mandatory ; it is a convention. But it is very helpful to make the difference between Class and instances.


Could you show all the init in cbaseController.

It is surprising that they have an init(), for a NSWindowController.


What happens when you remove the following init() :

open class clistWindow: cbaseController{
    public override init () {
        super.init()
    }

for cbaseController, the initializers are:


public init() {

self.ctrls = nil

self.tabView = nil

self.tabviewSelected = nil

self .boutonsToolbar = nil

self.currentFocus = nil

self.myPopover = nil

self.popoverViewController = nil

self .docPopoverController = nil

self.documentPopover = nil

self.timerDocument = nil

self.indicator = nil

self.tableCourante = nil

super.init(window: nil)

register()

let content: NSView = (window?.contentView)!

//if (window is clWindow) {

// (window as! clWindow).myController = self

//}

//ctrls = myControles()

setControls(view: content, tabviewItem: nil)

setConfigs()

setState(etat: .nonedition)

}

override public init(window: NSWindow?) {

self.ctrls = nil

self.tabView = nil

self.tabviewSelected = nil

self .boutonsToolbar = nil

self.currentFocus = nil

self.myPopover = nil

self.popoverViewController = nil

self .docPopoverController = nil

self.documentPopover = nil

self.timerDocument = nil

self.indicator = nil

self.tableCourante = nil

super.init(window: nil)

register()

let content: NSView = (window?.contentView)!

//if (window is clWindow) {

// (window as! clWindow).myController = self

//}

//ctrls = myControles()

setControls(view: content, tabviewItem: nil)

setConfigs()

setState(etat: .nonedition)

}

required public init?(coder: NSCoder) {

super.init(coder:coder)

}

cbaseController is an NSWindowController ?


Sorry if you already told about this:

What happens when you remove the following init() :

open class clistWindow: cbaseController{ 
    public override init () { 
        super.init() 
    }

Yes, cbaseConroller is an NSWIndowController


if I remove the public override init() initializer, I still have he error "Initializer does not override a designated initializer from its superclass"

on init(window: NSWindow!)


I think I'm not good enough to make frameworks. Did I tell you that the framework I try to build is linked with AlamoFire? I don't think it is the problem, for the moment, but perhaps it has impact on my framework


an other thing: I made an IOS framework with the RayWenderlich creating a framework for IOS. When I link this framework to the main project, in XCode, I can see all the files of the framework in the main project.


But when I link my framework to tyhe main macOS project, I only see a reference to the framework, not the files.


Does this help?

The Swift initialisation process can be very confusing. I recommend that you read the Class Inheritance and Initialization section of The Swift Programming Language before going on.

To sort this out you need to decide, at each level of the class hierarchy, which initialisers are designated and which initialisers are convenience. Reading through your post it seems that you have four levels of inheritance:

  • NSWindowController
  • CBaseWindowController
  • CListWindowController
  • MOTSWindow
NSWindowController
has two designated initialisers, namely
init(window:)
and
init?(coder:)
. What initialisers do you want at the other levels?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I think I begin to understand


I had confusion between workspace and xcworkspace

In my main projet, I have to add the .xcworkspace file, and in embedded libraries, I have to add the product framework which doesn't contains Alamofire. By doing this, in motsWindow, I can import a reference to the framework.

Then when I call the init(window:) there is no error


Do you think it's correct?

This reading could be helpful:

h ttps://stackoverflow.com/questions/21631313/xcode-project-vs-xcode-workspace-differences

I made the framework, with your recommandations.

So in the main project, motsWindow is initialized calling motsWindow(window: nil)


of course, it is not good because there is no window loaded.

So, I wonder how to load the correct window from the Nibfile and initialize motsWindow

To load from nib, call


init(windowNibName:)


Declaration

convenience init(windowNibName: NSNib.Name)
apple-reference-documentation://hs9xSPl-raapple-reference-documentation://hsBBskK7nL

Parameters

windowNibName

The name of the nib file (minus the “

.nib
” extension) that archives the receiver’s window; cannot be
nil
.

Discussion

Sets the owner of the nib file to the receiver. The default initialization turns on cascading, sets the

shouldCloseDocument
property to
false
, and sets the autosave name for the window’s frame to an empty string.

Yes Claude, I know that


But init(windowNibName:) is not a designated initializer, so I can't call it from a frameWork

Framework integration
 
 
Q