Posts

Post not yet marked as solved
4 Replies
3.3k Views
Hello: I am adding a video file to my MAC application. Before I create an archive, the video plays perfectly but when I run a copy of the archive, when I click on the button to start the video, NOTHING HAPPENS. No error message, Nothing. Any help to resolve this issue will be appreciated. Here is the code: This code: @IBAction func AVSegue(_ sender: Any) { let mainStoryboard = NSStoryboard(name: "Main", bundle: Bundle.main) guard let avPlayerViewController = mainStoryboard.instantiateController (withIdentifier: "AVID") as? AVPlayerViewController else { print("Couldn't find viewController" )         return         } presentAsModalWindow(avPlayerViewController)   } triggers the ViewController with the AV Player: import Cocoa import AVKit import AVFoundation class AVPlayerViewController: NSViewController {     @IBOutlet weak var playerView: AVPlayerView!         override func viewDidLoad() { super.viewDidLoad()             let url = URL(fileURLWithPath: Bundle.main.path(forResource:"SMRIntro",ofType: "mp4")!)             let player = AVPlayer(url: url)             playerView.player = player             player.play()           } }
Posted
by wlionel.
Last updated
.
Post not yet marked as solved
2 Replies
2.8k Views
Hello:I have been struggling with this small piece of code foe days. Every time I resolve one problem with it, another one pops up:I seem to have resolved the problem of "Expected Pattern" but now I have the problem "Cannot call value of non-function type '[String]'Here is the code:var name = [String]() override func viewDidLoad() { super.viewDidLoad() let persistentContainer = NSPersistentContainer(name: "No_Regrets") persistentContainer.loadPersistentStores { (_, error) in if let error = error { fatalError("Failed to load Core Data stack: \(error)") } } // Creates a task with a new background context created on the fly persistentContainer.performBackgroundTask { (context) in //iterates the array let Gains = [self.gain1, self.gain2, self.gain3, self.gain4] Gains.forEach {_ in // Creates a new entry inside the context `context` and assign the array element `name` to the dog's name let gain1 = Gains(context: context) //Cannot call value of non-function type '[String]' gain1.name = name let gain2 = Gains(context: context) //Cannot call value of non-function type '[String]' gain2.name = name let gain3 = Gains(context: context) //Cannot call value of non-function type '[String]' gain3.name = name let gain4 = Gains(context: context) //Cannot call value of non-function type '[String]' gain4.name = name } do { // Saves the entries created in the `forEach` try context.save() } catch { fatalError("Failure to save context: \(error)") } }
Posted
by wlionel.
Last updated
.
Post marked as solved
7 Replies
2.3k Views
Hello:I am creating a Menu Bar Extra Item for my MAC os App. I have the following code but nothing displays on the menu bar. W ould appreciate some advice on where in the code I need to make changes:import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { //@IBOutlet weak var window: NSWindow! let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength) // var item: NSStatusItem? = nil @objc func QuitScorCentMasterReview(_ sender: Any?) { NSApplication.shared.terminate(self) } func applicationDidFinishLaunching(_ aNotification: Notification) { if let button = statusItem.button { button.image = NSImage(named:NSImage.Name("SMR_icon.png")) button.action = #selector(QuitScorCentMasterReview(_:)) } func constructMenu() { let menu = NSMenu() menu.addItem(NSMenuItem(title: "End the Application", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "")) statusItem.menu = menu } constructMenu() }
Posted
by wlionel.
Last updated
.
Post not yet marked as solved
0 Replies
434 Views
Hello: I am trying to have my AVPlayer to automatically dismiss when Video completes. The code is giving me some problems with errors. Here is the code and errors. Hope some one can point me to a way to correct the errors:     @IBOutlet weak var playerView: AVPlayerView!      override func viewDidLoad() {          super.viewDidLoad()          guard let path = Bundle.main.path(forResource: "chosePrize", ofType:"mp4") else {               debugPrint("Not found")               return          }              let playerURL = AVPlayer(url: URL(fileURLWithPath: path))	                playerView.player = playerURL         NotificationCenter.defaultCenter.addObserver(self, selector: Selector(("playerDidFinishPlaying:")),         name: NSNotification.Name(name: AVPlayerDidPlayToEndTime, object: nil), //Use of unresolved identifier 'AVPlayerDidPlayToEndTime'         playerView.player?.play()     func donePlaying(notification:NSNotification) // Expected ')' in expression list {             print("video ended")            }          // Do view setup here.     } }
Posted
by wlionel.
Last updated
.
Post not yet marked as solved
1 Replies
535 Views
My Mac OS app was running fine until today when my TabView Controller ceased to load images for the pop-up (xy) button to display. When I checked the connection there was this error message: Container View does not have a IBSegueTriggerViewDidLoad binding. Below the Triggered Segues is ViewDidLoad and Below the Connection tab is Tab View Controller: Embed with the yellow caution icon. By hovering over the icon I see the above error. What can I do to reconnect this binding? I deleted the connection and redo the segue but the error comes back. Any help will be appreciated.
Posted
by wlionel.
Last updated
.
Post not yet marked as solved
1 Replies
555 Views
I want to run my Mac App developed on iMAC, on My MacBook Air. I used Xcode Archive utility to create a copy which I transferred to a Flash Drive and copied to my MacBook. When I run the app, none of the data in my CoreData entities are there.How can I archive my app to include the CoreData stores?Thanks
Posted
by wlionel.
Last updated
.
Post marked as solved
17 Replies
4.3k Views
Hello:I've read just about every thing I could find about animations in my MAC OSx app. However, I've not been able to find a useful tutorial of example. Nearly All the examples i found are for iOS and all of those animations are initiated by tapping a button.I want to be able to make the image on my main window Zoom in from a small icon to fill the window in a gradual zoom in motion as the app main View is loaded.I will appreciate any example, tutorial, or Swift resource that could be useful in solving this problem.Thanks in Advance.
Posted
by wlionel.
Last updated
.
Post not yet marked as solved
4 Replies
2.4k Views
Hello:I have successfully read data from a plist and want to save that data to CoreData. From the code below I am not getting errors but it is not saving the plist data.Please suggest what I am missing:func preloadScq() { print("Call to preload Data Starts Now") let preloadedDataKey = "didPreloadData" UserDefaults.standard.removeObject(forKey: preloadedDataKey) let userDefaults = UserDefaults.standard if userDefaults.bool(forKey: preloadedDataKey) == false { guard let plistUrl = Bundle.main.url(forResource: "SCQ", withExtension:"plist") else { return } let backgroundContext = persistentContainer.newBackgroundContext() persistentContainer.viewContext.automaticallyMergesChangesFromParent = true backgroundContext.perform { let scqObjects = NSEntityDescription.insertNewObject(forEntityName: "SCQ", into: backgroundContext) if let arrayContents = NSArray(contentsOf: plistUrl) as? [String] { do { let plistData = try Data(contentsOf: plistUrl) let scqList = try PropertyListDecoder().decode([Scq].self, from: plistData) for scqName in scqList { let scqObject = SCQ(context: backgroundContext) scqObject.answer = "answer" // the first object in the plist print ("Answer is \(scqObject)") // This doesn't print anything } try backgroundContext.save() } catch { print(error) print ("Your Record is Saved") } } } //
Posted
by wlionel.
Last updated
.
Post marked as solved
7 Replies
2.2k Views
Hello:I am getting the error Value of Type Bool has no subscripts in bellow code but can't figure out how to resolve it. Any help will be appreciated.The error is on line # 19. That line is supposed to call first record and continue with subsequest records in the plist.func preloadData() { print ("Call to preload Data Starts Now") let preloadedDataKey = "didPreloadData" UserDefaults.standard.removeObject(forKey: preloadedDataKey) let userDefaults = UserDefaults.standard if userDefaults.bool(forKey: preloadedDataKey) == false { guard Bundle.main.url(forResource: "SCQ", withExtension:"plist") != nil else { return } var propertyListFormat = PropertyListSerialization.PropertyListFormat.xml //format the property list var plistData: [String: AnyObject] = [:] // the data print(plistData) let plistUrl = Bundle.main.url (forResource: "SCQ", withExtension: "plist") // path of the data let fileManager = FileManager.default if let plistData = NSData(contentsOf: plistUrl!) { var format = PropertyListSerialization.PropertyListFormat.xml do { let items = PropertyListSerialization.propertyList(plistData, isValidFor: format) let item = items[0]// error here if let attribute = item ["answer"] { print (item) } if let attribute = item ["distractor1"] { print (item) } if let attribute = item ["distractor2"] { print (item) } if let attribute = item ["distractor3"] { print (item) } if let attribute = item ["distractor4"] { print (item) } if let attribute = item ["distractor5"] { print (item) } if let attribute = item ["grade"] { print (item) } if let attribute = item ["id"] { print (item) } if let attribute = item ["answer"] { print (item) } if let attribute = item ["qid"] { print (item) } if let attribute = item ["question"] { print (item) } if let attribute = item ["qValue"] { print (item) } if let attribute = item ["skill"] { print (item) } if let attribute = item ["subject"] { print (item) } if let attribute = item ["topic"] { print (item) } } catch { print(error) } }
Posted
by wlionel.
Last updated
.
Post marked as solved
6 Replies
746 Views
Hello:I want to be able to check if a specific Core Data record was fetched previously by comparing the Record ID with the one being currently fetched. I want to some how to mark each fetched record so I can know whether or not it has been called before.I don't want to save every fetched record to a data store then compare new fetches with what is there because it would call for a lot of processing resources.Is there an easier way?Thanks.
Posted
by wlionel.
Last updated
.
Post not yet marked as solved
2 Replies
1.8k Views
Hello:I want to capture the input value in a text field into a variable. Here is my code:var window: NSWindow? func checkGroupName() { let alert = NSAlert() alert.messageText = "Please enter your group name" alert.addButton(withTitle: "Save") alert.addButton(withTitle: "Cancel") let inputTextField = NSTextField(frame: NSRect(x: 0, y: 0, width: 300, height: 24)) inputTextField.placeholderString = ("Enter your group name") alert.accessoryView = inputTextField alert.runModal() let object = NSTextField() let value = object.stringValue print("The value of Group Name is \(value)") }What should I add to the above code to get the value entered in a variable i can use later in the code? "value" above is empty.
Posted
by wlionel.
Last updated
.
Post not yet marked as solved
2 Replies
913 Views
Hello:I am trying to get my users to provide some information to use in the app by present an alert as the user begins. My code is causing a crash with fatal error Unexpectedly found nil while unwrapping an Optional value (line 13). var window: NSWindow? func checkGroupName() { let alert = NSAlert() alert.messageText = "Please enter your group name" alert.addButton(withTitle: "Save") alert.addButton(withTitle: "Cancel") let inputTextField = NSTextField(frame: NSRect(x: 0, y: 0, width: 300, height: 24)) inputTextField.placeholderString = "Enter group name" alert.accessoryView = inputTextField alert.beginSheetModal(for: self.view.window!, completionHandler: { (modalResponse) -> Void in if modalResponse == NSApplication.ModalResponse.alertFirstButtonReturn { let enteredString = inputTextField.stringValue print("Entered string = \"\(enteredString)\"") } }) }What is causing the error?
Posted
by wlionel.
Last updated
.
Post marked as solved
7 Replies
1.1k Views
Hello:I have this code and getting error:Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional valueWhat can I do to prevent the error? Here is the code:class ViewController: NSViewController,NSWindowDelegate { var window: NSWindow! override func viewDidLoad() { super.viewDidLoad() } func windowShouldClose(sender: AnyObject) -> Bool { NSApp.hide(nil) return false } override func awakeFromNib() { super.awakeFromNib() view.window!.delegate! = self //Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value }Thanks for help.
Posted
by wlionel.
Last updated
.
Post marked as solved
1 Replies
496 Views
Hello:I am trying to open a Storyboard View from an @IBAction but the app crashes with no log output. Any help will be appreciated.Below is the code. Lines 10 to 18 are highlighted in the code when the crash occurs.@IBActionfunc launchMainMenu(_ sender: NSMenuItem) { if ((mainWindowController) == nil){ var windowController : NSWindowController? let storyboard = NSStoryboard() func openMyWindow() { if let vc = storyboard.instantiateController(withIdentifier: "4554") as? ViewController { let myWindow = NSWindow(contentViewController: vc) myWindow.makeKeyAndOrderFront(self) let controller = NSWindowController(window: myWindow) controller.showWindow(self) } } openMyWindow() } }
Posted
by wlionel.
Last updated
.
Post not yet marked as solved
14 Replies
3k Views
Hello:Since the beginning of March, I have been trying to respond to a demand by Apple without success:The requirement is that when a user closes the main window of my app by clicking on the red x, I must they must be able to relaunch the main window from a menu.I have been able to hide the window and relaunch it beu am unable to relaunch the window when the red x is clicked, EVEN THOUGH THE APP ICON IS STILL ON THE DOCK.I hope someone can point me in the right direction. Here is my code: (I'm sure I have stuff here I don't need. Would appreciate to know which lines to cut.import Cocoa import ServiceManagement @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var showMainMenu: NSMenu! var window: NSWindow! var statusBarItem: NSStatusItem? func applicationDidFinishLaunching(_ aNotification: Notification) { window = NSApplication.shared.windows[0] let statusBar = NSStatusBar.system statusBarItem = statusBar.statusItem( withLength: NSStatusItem.squareLength) let itemImage = NSImage(named: "SMR_icon") itemImage?.isTemplate = true statusBarItem?.button?.image = itemImage statusBarItem?.button?.action = #selector(self.statusBarButtonClicked(sender:)) statusBarItem?.button?.sendAction(on: [.leftMouseUp, .rightMouseUp]) // << send action in both cases let statusBarMenu = NSMenu(title: "Status Bar Menu") statusBarMenu.addItem( withTitle: "Launch ScorCent Master Review", action: #selector(AppDelegate.LaunchScorCentMasterReview), keyEquivalent: "") statusBarMenu.addItem( withTitle: "Quit ScorCent Master Review", action: #selector(AppDelegate.QuitScorCentMasterReview), keyEquivalent: "") statusBarMenu.addItem( withTitle: "Terminate ScorCent Master Review", action: #selector(AppDelegate.StopScorCentMasterReviewApplication), keyEquivalent: "") // Setting menu statusBarItem?.button?.menu = statusBarMenu // << store menu in button, not item } @IBAction func LaunchWindowMain(_ sender: NSMenuItem) { func applicationShouldHandleReopen(theApplication: NSApplication, hasVisibleWindows flag: Bool) -> Bool { if !flag{ window.makeKeyAndOrderFront(nil) for window: AnyObject in theApplication.windows { window.makeKeyAndOrderFront(self) } } return true } } @objc func statusBarButtonClicked(sender: NSStatusBarButton) { let event = NSApp.currentEvent! if event.type == NSEvent.EventType.leftMouseUp { print("Left click!") if let button = statusBarItem?.button { // << pop up menu programmatically button.menu?.popUp(positioning: nil, at: CGPoint(x: -1, y: button.bounds.maxY + 5), in: button) } } else { print("Left click!") } } @objc func QuitScorCentMasterReview(_ sender: Any?) { NSApplication.shared.hide(QuitScorCentMasterReview) print("Close the App") } @objc func LaunchScorCentMasterReview(_ sender: NSStatusBarButton) { NSApplication.shared.unhide(AppDelegate.LaunchScorCentMasterReview) NSApplication.shared.unhide(AppDelegate.init()) print("Launch the App") } @objc func StopScorCentMasterReviewApplication(_sender: Any?) { NSApplication.shared.terminate(AppDelegate.StopScorCentMasterReviewApplication) print("Stop the App") } func applicationWillTerminate(_ aNotification: Notification) { }
Posted
by wlionel.
Last updated
.