Posts

Post not yet marked as solved
4 Replies
I discovered the reason for the video not playing: I did not include the AVKit.Framework in the link library. Be sure to include the following in Link Library With Libraries(Build Phases) AVKit.Framework AVFoundation.Framework
Post not yet marked as solved
4 Replies
The AVPlayer does not show at all. When I click on the link to trigger the segue to the AVPlayer Controller, I get absolutely no response. When I do the same with the run project in Xcode project the player loads and the video plays normally.
Post marked as solved
17 Replies
Hello 00per:Your code works beautifully!!Thanks a million. You're the greatest.
Post marked as solved
17 Replies
Hi Guys,I am using Xcode version 11.5. I don't know if that has anything to do with the issues i am experiencing but with the width and height of the ImageView set to 48 and priority 750, the app still crashes with the error "Unexpectedly found nil while implicitly unwrapping an Optional value: file" on line18import Cocoa class ViewController: NSViewController { @IBOutlet weak var imageView: NSImageView! //imageView, its center constrained, //width and height are not constrained in the storyboard var widthConstraint: NSLayoutConstraint! var heightConstraint: NSLayoutConstraint! override func viewDidLoad() { super.viewDidLoad() widthConstraint = imageView.widthAnchor.constraint(equalToConstant: 48) widthConstraint.isActive = true heightConstraint = imageView.heightAnchor.constraint(equalToConstant: 48) heightConstraint.isActive = true imageView.image = NSImage(named: "icon.jpg") } override func viewWillAppear() { super.viewWillAppear() NSAnimationContext.runAnimationGroup({context in context.duration = 1.0 widthConstraint.animator().constant = self.view.frame.width heightConstraint.animator().constant = self.view.frame.height }) { print("Animation finished") //Do some UI updates on animation finished, if you need... } } } var representedObject: Any? { didSet { // Update the view, if already loaded. } }
Post marked as solved
17 Replies
Hello 00per:Don't know if you saw my response. It been saying "Currently Being Moderated" for quite a while.When I run the code the image doesn't show and the debug has a very long set of NSLayoutConstraints problems after "Unable to simultaneously satisfy constraints"
Post marked as solved
17 Replies
Hello Claude31:Removing the commas generate all the errors in my previous reply. The only error that persists with the commas in place is // "Expected Expression". The three expressions aftersizeInMotion = ...posInMotion = ...frameInMotion = ...generate the same error "Missing Expression" depending on where the parentheses are located.The code below generates the single error, but calls for a semicolon at the end of line 5 in addition to the comma. This syntax is very difficult to decipher for some reason. for i in 0...100 { usleep(hundredthSecond) ratio = CGFloat(i)/100 DispatchQueue.main.async { //This is a UI Function sizeInMotion = CGSize(width: ratio * fullSize.width / 100, height: ratio * fullSize.height / 100);, posInMotion = CGPoint(x: 1 ratio * fullWindowPosition.x/100, y: ratio * fullWindowPosition.y/100), frameInMotion = NSRect(origin: posInMotion, size: sizeInMotion), self.view.frame(sizeInMotion) } }
Post marked as solved
17 Replies
Hi janabanana,Thanks for the reply. I made the change and added a comma (,) at the end of line 5With that change I get 2 errors:1. Consecutive statements on a line must be separated by ';'2. Expected expressionIf I don't use the comma at the end of that line, or add a semicolon I get a bunch of errors.1. Cannot call value of non-function type 'Int'2. Consecutive statements on a line must be separated by ';'3. Expected expression4. Value of type '(NSWindow) -> () -> Void' has no member 'x'5. Value of type '(NSWindow) -> () -> Void' has no member 'y'Where do you think the problem is?for i in 0...100 { usleep(hundredthSecond) ratio = CGFloat(i)/100 DispatchQueue.main.async { //This is a UI Function sizeInMotion = CGSize(width: ratio * fullSize.width / 100 , height: ratio * fullSize.height / 100), posInMotion = CGPoint(x: 1 (ratio * fullWindowPosition.x/100), y: ratio * (fullWindowPosition.y/100)), frameInMotion = NSRect(origin: posInMotion, size: sizeInMotion) // self.view.frame(sizeInMotion) } }
Post marked as solved
17 Replies
Hello Claude31:I think i've made some progress in coding this thing but can't run it because of compiler complaining that code in lines 19 - 21 is too comples to compile within reasonable time. Is there is a way to break up that code into smaller pieces? I can't see it.overridefunc viewWillAppear() { let offsetFromLeft = CGFloat(200) let offsetFromBottom = CGFloat(200) let hundredthSecond = UInt32(5_000) // Go fast 1/200e s in fact let fullSize = CGRect(x: 0,y: 0,width: self.view.frame.height * 0.9, height: self.view.frame.width * 0.4) let fullWindowPosition = self.window.center var posInMotion = CGPoint.zero var sizeInMotion = CGSize.zero var frameInMotion = CGRect.zero var ratio = CGFloat(0) for i in 0...100 { usleep(hundredthSecond) ratio = CGFloat(i)/100 DispatchQueue.main.async { // Car c'est une fonction UI ; sizeInMotion = CGSize(width: ratio * fullSize.width / 100 , height: ratio * fullSize.height / 100) posInMotion = CGPoint(x: 1 (ratio * fullWindowPosition.x/100, y: ratio * (fullWindowPosition.y/100))) frameInMotion = NSRect(origin: posInMotion, size: sizeInMotion) // self.view.frame(sizeInMotion) } } }
Post marked as solved
17 Replies
I am having some difficulty getting this code to compile. Below are some changes made to the code with the errors:overridefunc viewWillAppear() { let offsetFromLeft = CGFloat(200) let offsetFromBottom = CGFloat(200) let centiemeSeconde = UInt32(5_000) // Go fast 1/200e s in fact let fullSize = NSWindow(contentRect: NSRect(x:0,y:0, width: 800, height: 500),styleMask: [.titled, .resizable], backing: .buffered, defer: false) let fullWindowPosition = self.window.center var posInMotion = CGPoint.zero var sizeInMotion = CGSize.zero var frameInMotion = CGRect.zero var ratio = CGFloat(0) for i in 0...100 { usleep(centiemeSeconde) ratio = CGFloat(i) DispatchQueue.main.async { // Car c'est une fonction UI ; sizeInMotion = CGSize(width: ratio * fullSize.width / 100 , height: ratio * fullSize.height / 100) // Value of type 'NSWindow' has no member 'height' / posInMotion = CGPoint(x: 1 (ratio * fullWindowPosition.x/100, y: ratio * (fullWindowPosition.y/100))) //The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions Value of type 'NSWindow' has no member 'width' frameInMotion = NSRect(origin: posInMotion, size: sizeInMotion) self.imageView.setFrame(sizeInMotion) //Type 'NSImageView' has no member 'setFrame' } } }Any additional help will be appreciated.
Post not yet marked as solved
4 Replies
Hello Calude31:After a week of struggle with your and 00per's suggestions, I finallg figured out the solution and as usual it was really a simple fix:func preloadScq() { let backgroundContext = persistentContainer.newBackgroundContext() persistentContainer.viewContext.automaticallyMergesChangesFromParent = true _ = NSEntityDescription.entity(forEntityName: "SCQ", in: backgroundContext)! 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 } do { typealias Settings = [Scq] var settings: Scq? let plistData = try Data(contentsOf: plistUrl) let scqList = try PropertyListDecoder().decode([Scq].self, from: plistData) print(scqList) for items in scqList { print("These are the \(items)") let entity = NSEntityDescription.entity(forEntityName: "SCQ", in: backgroundContext)! let newEntity = NSManagedObject(entity: entity, insertInto: backgroundContext) newEntity.setValue(items.answer, forKeyPath: ("answer" as? String)!)//This line did the trick print ("This is the new entity \(items.answer)") try backgroundContext.save() print("SAVED") } } catch { print(error) } }Thanks.
Post not yet marked as solved
4 Replies
Hello Claude31:I edited the code as below and am getting a debug list as below:func preloadScq() { let backgroundContext = persistentContainer.newBackgroundContext() persistentContainer.viewContext.automaticallyMergesChangesFromParent = true _ = NSEntityDescription.entity(forEntityName: "SCQ", in: backgroundContext)! 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 } do { let plistData = try Data(contentsOf: plistUrl) let scqList = try PropertyListDecoder().decode([Scq].self, from: plistData) let scqObjects = NSEntityDescription.insertNewObject(forEntityName: "SCQ", into: backgroundContext) print(scqList) for scqName in scqList { let scqObject = SCQ(context: backgroundContext) // print(scqName) scqObject.answer = ("answer") print(scqName) } try backgroundContext.save() print("SAVED") // userDefaults.set (true, forKey: preLoadedDataKey) } catch { print(error) } } }I get a print of the plist contents:[ScorCentMasterReview.AppDelegate.Scq(answer: "1", distractor1: "R", distractor2: "Wr", distractor3: "DK", distractor4: "not here", distractor5: "not here", grade: "2", id: "403", qid: "1", question: "If the word is spelled correctly choose R. If it is not spelled correctly choose Wr. If you don’t know choose DK. The noise was TERRIBLE.", qValue: "1000", skill: "Spell Terrible Correctly", subject: "ELA", topic: "SPELLING")But The object that is saved is not the value for "answer" but the word "answer":CoreData: sql: INSERT INTO ZSCQ(Z_PK, Z_ENT, Z_OPT, ZANSWER, ZDIFFICULTYLEVEL, ZDISTRACTOR1, ZDISTRACTOR2, ZDISTRACTOR3, ZDISTRACTOR4, ZDISTRACTOR5, ZGRADE, ZID, ZQVALUE, ZQID, ZQUESTION, ZSKILL, ZSUBJECT, ZTOPIC) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)CoreData: details: SQLite bind[0] = (int64)2545CoreData: details: SQLite bind[1] = (int64)7CoreData: details: SQLite bind[2] = (int64)1CoreData: details: SQLite bind[3] = "answer"
Post marked as solved
7 Replies
Hello 00per:I found out the reason for the lack of print output. The plist keys were inserted with the "z" sqlite letter appended to each field.However only the first record is printed so Included a loop
Post marked as solved
7 Replies
Hello 00per:Thanks for the code. Seems I still need to add spme code because the print statements for the items do not print.What do you see as the reason? Could it be because the keys are not arranged in the same order as in the code?<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><array><dict> <key>zgrade</key> <string>2</string> <key>ztopic</key> <string>SPELLING</string> <key>z_pk</key> <string>2</string> <key>zdistractor1</key> <string>R</string> <key>zqid</key> <string>1</string> <key>zdistractor2</key> <string>Wr</string> <key>zdifficultyLevel</key> <string>92</string> <key>zdistractor3</key> <string>DK</string> <key>zid</key> <string>403</string> <key>zdistractor4</key> <string>not here</string> <key>zqValue</key> <string>1000</string> <key>z_ent</key> <string>3</string> <key>zdistractor5</key> <string>not here</string> <key>z_opt</key> <string>4</string> <key>zskill</key> <string>Spell Terrible Correctly</string> <key>zquestion</key> <string>If the word is spelled correctly choose R. If it is not spelled correctly choose Wr. If you don’t know choose DK. The noise was TERRIBLE.</string> <key>zanswer</key> <string>1</string> <key>zsubject</key> <string>ELA</string></dict><array></plist>
Post marked as solved
6 Replies
Hello Claude31:Thanks.I am thinking of another solution that may have an advantage. That is, Since I loaded all the records I want to use into a temporary Entity, I can delete the record that was fetched. (This entity is refreshed each time the user changes certain predicates).However, I would like to create the dictionary as you suggested, but I've not created one before manually (I've used in Core Data to find UNIQUE records, but core data does the work).Could you provide a sample code?(I'll accept the last suggestion as the correct answer.)