I'm new to Xcode development so this question might be silly but when I create an iMessage project by selection "iMessage Application" template. And I want it to be standalone app for iMessage so that there is no iOS app as I don't see it useful in my case. I notice that there is only StoryBoard in the project and it looks a little bit different than iOS project. I watched Stanford iOS course 2020 so I'm use to SwiftUI and would prefer using it.
Replies
Yes, you have to
- Delete the storyboard file and delete the NSExtensionMainStoryboard property and add NSExtensionPrincipalClass that will be the class MessagesViewController and this your MSMessagesAppViewController.
- Add to your code
@objc(MessagesViewController)
- In viewDidLoadMethod insert
// Get the UIKit view of your SwiftUI View
let child = UIHostingController(rootView: SwiftUIView())
self.view.addSubview(child.view)
// Set the place where your view will be displayed
let constraints = [
child.view.topAnchor.constraint(equalTo: view.topAnchor),
child.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
child.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
child.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
child.view.widthAnchor.constraint(equalTo: view.widthAnchor),
child.view.heightAnchor.constraint(equalTo: view.heightAnchor)
]
view.addConstraints(constraints)
Hope it will help you !
Post not yet marked as solved
Up vote reply of AntoineBollengier
Down vote reply of AntoineBollengier
-
I forgot, you have to add
child.view.translatesAutoresizingMaskIntoConstraints = false
after declaring child. -
I forgot, you have to add
child.view.translatesAutoresizingMaskIntoConstraints = false
after declaring child.
Would also like to know, bump