Post

Replies

Boosts

Views

Activity

Reply to How do I get this if statement to work?
First of all, in your shown code, braces are not balancing. I guess you need to put a closing brace at line 17. Second, your setupTable adds a new SKSpriteNode depending on the value of playerScore at the time of call. If you want your background to be changed according to playerScore, you need to run a code to change the background at each time playerScore changes.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20
Reply to Link in a label or a text view and macOS
In macOS it gives me two errors: Value of type NSScrollView has no member textStorage   Value of type NSScrollView has no member linkTextAttributes Seems you have put a Scrollable Text View into your view controller and connected it to an IBOutlet. There may be this line in your code: &#9;&#9;@IBOutlet weak var textView1: NSScrollView! Your outlet textView1 is connected to an NSScrollView, not an NSTextView. You can find the actual instance of NSTextView when you open up the view hierarchy in the Outline view (left side of Interface Builder):   ▼ Text View1    ▼ Clip View     ▼ Text View&#9;&#9;<-- This is the actual `NSTextView` Ctrl-drag from the Text View to your view controller and create another IBOutlet. Assuming you named it contentTextView, you will have this line: &#9;&#9;@IBOutlet var contentTextView: NSTextView! You can name it as you like, but the important thing is that Xcode has automatically chosen NSTextView for its type. With this right outlet, your code would work as expected: &#9;&#9;&#9;&#9;let attributedString = NSMutableAttributedString(string: "Just click here to register") &#9;&#9;&#9;&#9;let range = NSRange(location: 5, length: 10) &#9;&#9;&#9;&#9;let url = URL(string: "https://www.google.com")! &#9;&#9;&#9;&#9;attributedString.setAttributes([.link: url], range: range) &#9;&#9;&#9;&#9;contentTextView.textStorage?.setAttributedString(attributedString) &#9;&#9;&#9;&#9;contentTextView.linkTextAttributes = [ &#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor: NSColor.blue, &#9;&#9;&#9;&#9;&#9;&#9;.underlineStyle: NSUnderlineStyle.single.rawValue&#9;//<- Xcode suggested me to fix this line &#9;&#9;&#9;&#9;]
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20
Reply to Dictionary Subscript getter crash
I suspect this might be related with dictionaries not being accessed in a safe way due the use of several threads(?) Very likely. Do you think a .async(flags: .barrier) could solve the issue? Not sure. A reliable way, create a serial queue and touch the dictionary (or any other thread-unsafe objects) only in that queue. (I mean both read and write with touch.)
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20
Reply to Pop-up scheduled at fixed time
You should better check the User Notification framework. You can schedule repeated local notifications. Scheduling a Notification Locally from Your App - https://developer.apple.com/documentation/usernotifications/scheduling_a_notification_locally_from_your_app
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20
Reply to Link in a label or a text view and macOS
Do you know how to change the cursor on hover the link? Frankly, I did not know how, but could find some articles like this soon. How to change cursor on hover NSTextView? Swift 4, Xcode 9.4 - https://stackoverflow.com/a/56127308/6541007 Try adding an attribute to linkTextAttributes. &#9;&#9;&#9;&#9;contentTextView.linkTextAttributes = [ &#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor: NSColor.blue, &#9;&#9;&#9;&#9;&#9;&#9;.underlineStyle: NSUnderlineStyle.single.rawValue, &#9;&#9;&#9;&#9;&#9;&#9;.cursor: NSCursor.pointingHand, //<- &#9;&#9;&#9;&#9;]
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20
Reply to Internal structure(?) of optional mark
Starting with the question mark, Int? is a short cur form of Optional<Int>. Optional is an enum type, and Swift compiler has many builtin features to support Optionals. The exclamation mark is a little bit more complicated. Int! is equivalent to Optional<Int> as well as Int?. But Swift compiler adds some hidden attribute implicitly unwrapped to the variables declared using !. How can I call those marks? How to call depends on each person, but you can find some documents with Optional and Implicitly Unwrapped Optional. The latter is sometimes abbreviated as IUO. Can I check a developer document or internal source about those? Documentation of enum type Optional is available in the doc of Swift Standard Library. Optional - https://developer.apple.com/documentation/swift/optional Swift compiler is open source and you can check the source of it in a GitHub repository. https://github.com/apple/swift But it may be very hard to find which parts of the compiler and the runtime code are for supporting Optionals.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20
Reply to How do I get this if statement to work?
The whole code for setUpTable function is below along with the game scene. Thanks for showing your code. That will help understanding what is your current problem and thinking how to fix it. As I wrote before, you need to run a code to change the background at each time playerScore changes. There's no code to change the background in your GameScene. You are not doing anything to change the background on playerScore changes. (Your setupTable() is called only once when didMove(to:) is executed, not on playerScore changes.) For adding a code to change the background, you should better define a type representing the type of the background. enum TableType: String { &#9;&#9;case ovaloffice &#9;&#9;case austin &#9;&#9;case bond } extension TableType { &#9;&#9;static func `for`(score: Int) -> TableType { &#9;&#9;&#9;&#9;switch score { &#9;&#9;&#9;&#9;case 0...19: &#9;&#9;&#9;&#9;&#9;&#9;return .ovaloffice &#9;&#9;&#9;&#9;case 20...29: &#9;&#9;&#9;&#9;&#9;&#9;return .austin &#9;&#9;&#9;&#9;default: &#9;&#9;&#9;&#9;&#9;&#9;return .bond &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;var imageName: String {rawValue} } And to change the background a little bit efficiently at each time playerScore changes, you need some properties to add and modify one property. &#9;&#9;var tableType: TableType = .ovaloffice &#9;&#9;var playerScore = 0 { &#9;&#9;&#9;&#9;didSet(newScore) { &#9;&#9;&#9;&#9;&#9;&#9;let newTableType = TableType.for(score: newScore) &#9;&#9;&#9;&#9;&#9;&#9;//Call `replaceTable()` only on `tableType` did change &#9;&#9;&#9;&#9;&#9;&#9;if tableType != newTableType { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;tableType = newTableType &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;replaceTable() &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;var currentTable: SKSpriteNode? The method replaceTable() would become something like this: &#9;&#9;func replaceTable() { &#9;&#9;&#9;&#9;//You need to remove existing `table` before adding new one &#9;&#9;&#9;&#9;if let table = currentTable { &#9;&#9;&#9;&#9;&#9;&#9;table.removeFromParent() &#9;&#9;&#9;&#9;&#9;&#9;currentTable = nil &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;let table = SKSpriteNode(imageNamed: tableType.imageName) &#9;&#9;&#9;&#9;addChild(table) &#9;&#9;&#9;&#9;table.position = CGPoint(x: size.width/2, y: size.height/2) &#9;&#9;&#9;&#9;table.zPosition = -1 &#9;&#9;&#9;&#9;//If you need to modify some properties based on the `tableType`, uncomment the following switch statement &#9;&#9;&#9;&#9;/* &#9;&#9;&#9;&#9;switch tableType { &#9;&#9;&#9;&#9;case .ovaloffice: &#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;&#9;&#9;break &#9;&#9;&#9;&#9;case .austin: &#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;&#9;&#9;break &#9;&#9;&#9;&#9;case .bond: &#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;&#9;&#9;break &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;*/ &#9;&#9;} You can modify your setupTable() using it: &#9;&#9;func setupTable() { &#9;&#9;&#9;&#9;replaceTable() &#9;&#9;&#9;&#9;addChild(moneyContainer) &#9;&#9;&#9;&#9;moneyContainer.anchorPoint = CGPoint(x:0, y:0) &#9;&#9;&#9;&#9;//... &#9;&#9;} The code above is not tested and I may be missing something important to show, but please try. If you find something wrong with my code, please tell me what's going wrong in detail.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20
Reply to Transfer From Parent To Child
How do I move this method to the child classes so it can update when a slider moves? It is very hard to say how without more context. How your parent class and child classes are defined? How a slider is used in each child class? How parent class and child class are related? Can you show more context?
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’20