Posts

Post not yet marked as solved
534 Views

Fill a RoundedRectangle with custom color

RoundedRectangle(cornerRadius: 8, style: .continuous) . foregroundColor(Color.init(red: 255, green: 245, blue: 158))My rounded rectangle is all white. Why can't I initiate a custom color? Whereas Color.red works perfectly fine?
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
89 Views

Does CTRubyAnnotationCreateWithAttributes work with UITextView?

I want to create ruby text for some Japanese kanji and I can get CTRubyAnnotationCreateWithAttributes to work with an attributed string inside a UILabel but not UITextView. Is there a way around this?
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
169 Views

NLTagger support for Japanese

Hi, I am trying to use the natural language tagger for Japanese. I used this sample code: var stringToRecognize = jpTextView.text &#9;&#9;let range = stringToRecognize!.startIndex ..< stringToRecognize!.endIndex &#9;&#9;let tagger = NLTagger(tagSchemes: [.lexicalClass]) &#9;&#9;tagger.string = stringToRecognize &#9;&#9;tagger.enumerateTags(in: range, unit: .word, scheme: .lexicalClass) { (tag, range) -> Bool in &#9;&#9;&#9;print("Word [\(stringToRecognize![range])] : \(tag!.rawValue)") &#9;&#9;&#9;return true &#9;&#9;} and applied it on some dummy data: 東京では11月から、コロナウイルスの病気で入院する人が多くなっています。このため、お腹の中に赤ちゃんがいる看護師も仕事を続けています。家に小さな子どもがいる看護師は、子どもにウイルスがうつらないか心配しながら仕事をしています。 The output was: Word [東京] : OtherWord Word [で] : OtherWord Word [は] : OtherWord Word [11] : OtherWord Word [月] : OtherWord Word [から] : OtherWord Word [、] : Punctuation Word [コロナ] : OtherWord Word [ウイルス] : OtherWord Word [の] : OtherWord Word [病気] : OtherWord Word [で] : OtherWord Word [入院] : OtherWord Word [する] : OtherWord Word [人] : OtherWord Word [が] : OtherWord Word [多く] : OtherWord Word [なっ] : OtherWord Word [て] : OtherWord Word [い] : OtherWord Word [ます] : OtherWord Word [。] : SentenceTerminator Word [この] : OtherWord Word [ため] : OtherWord Word [、] : Punctuation Word [お腹] : OtherWord Word [の] : OtherWord Word [中] : OtherWord Word [に] : OtherWord Word [赤ちゃん] : OtherWord Word [が] : OtherWord Word [いる] : OtherWord Word [看護] : OtherWord Word [師] : OtherWord Word [も] : OtherWord Word [仕事] : OtherWord Word [を] : OtherWord Word [続] : OtherWord Word [け] : OtherWord Word [て] : OtherWord Word [い] : OtherWord Word [ます] : OtherWord Word [。] : SentenceTerminator Word [家] : OtherWord Word [に] : OtherWord Word [小さな] : OtherWord Word [子ども] : OtherWord Word [が] : OtherWord Word [いる] : OtherWord Word [看護] : OtherWord Word [師] : OtherWord Word [は] : OtherWord Word [、] : Punctuation Word [子ども] : OtherWord Word [に] : OtherWord Word [ウイルス] : OtherWord Word [が] : OtherWord Word [うつら] : OtherWord Word [ない] : OtherWord Word [か] : OtherWord Word [心配] : OtherWord Word [し] : OtherWord Word [ながら] : OtherWord Word [仕事] : OtherWord Word [を] : OtherWord Word [し] : OtherWord Word [て] : OtherWord Word [い] : OtherWord Word [ます] : OtherWord Word [。] : SentenceTerminator It looks like every word is just being picked up as OtherWord, and it can detect some punctuation. Is this correct, or will there be an improvement to the Japanese tagger soon so we can differentiate between nouns, verbs, conjunctions, particles, etc. ?
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
123 Views

Rename 'Cancel' on modal sheet in SwiftUI

The Apple documentation gives some user interface design tips on modal sheets including renaming Cancel to something like Dismiss where relevant. But there's no guide whether this is possible in SwiftUI. There's a link that takes you to setTitle for Watchkit: https://developer.apple.com/documentation/watchkit/wkinterfacecontroller/1619570-settitle But is there something equivalent for SwiftUI on a Watch app?
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
205 Views

Highlight synthesized speech missing words

Hi, I'm using one of the delegate methods to determine when words are about to be spoken and then trying to provide a color background to indicate what is about to be spoken: func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance) { &#9;&#9;guard let rangeInString = Range(characterRange, in: utterance.speechString) else { return } &#9;&#9;print("Will speak: \(utterance.speechString[rangeInString])") &#9;&#9;let attributes: [NSAttributedString.Key: Any] = [ &#9;&#9;&#9;.foregroundColor: UIColor.darkText, &#9;&#9;&#9;.font: UIFont.systemFont(ofSize: 16) &#9;&#9;] &#9;&#9;let mutableAttributedString = NSMutableAttributedString(string: utterance.speechString, attributes: attributes) &#9;&#9;mutableAttributedString.addAttribute(.backgroundColor, value: UIColor.yellow, range: characterRange) &#9;&#9;jpTextView.attributedText = mutableAttributedString &#9;} Based on the debug log I can see that it is reading every word in my UITextView, but when it comes to the yellow background highlighting, it's quite inconsistent and seems to skip around half the words. Is this an inherent issue related to the language I'm using (Japanese) or is there something fundamental in my code that needs to be fixed?
Asked
by dshum17.
Last updated
.
Post marked as solved
278 Views

How to chain speech utterances

Hi, I spoke to someone during the audio lab today in relation to audio output of Chinese dialects. So I can now get cantonese and mandarin outputted. But now I'm trying to read the same line of text in both dialects, and the audio overlaps each other. What do I need to change in my code to create a pause between the two utterances rather than reading both at the same time? let cantoUtterance = AVSpeechUtterance(string: chinese) &#9;&#9;&#9;&#9;&#9;&#9;//utterance.voice = AVSpeechSynthesisVoice(language: "zh-HK") &#9;&#9;&#9;&#9;&#9;&#9;cantoUtterance.voice = AVSpeechSynthesisVoice(identifier: "com.apple.ttsbundle.Sin-Ji-compact") &#9;&#9;&#9;&#9;&#9;&#9;// utterance.rate = 0.1 &#9;&#9;&#9;&#9;&#9;&#9;let cantoSynthesizer = AVSpeechSynthesizer() &#9;&#9;&#9;&#9;&#9;&#9;cantoSynthesizer.speak(cantoUtterance) &#9;&#9;&#9;&#9;&#9;&#9;let mandoUtterance = AVSpeechUtterance(string: chinese) &#9;&#9;&#9;&#9;&#9;&#9;mandoUtterance.voice = AVSpeechSynthesisVoice(language: "zh-CN") &#9;&#9;&#9;&#9;&#9;&#9;let mandoSynthesizer = AVSpeechSynthesizer() &#9;&#9;&#9;&#9;&#9;&#9;mandoSynthesizer.speak(mandoUtterance)
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
189 Views

RevenueCat and watchOS

Has anyone had any luck with RevenueCat and independent watchOS apps? I am having trouble retrieving SKProducts that i setup on app store connect. Is there something different about Watch apps that I need to factor in the configuration of RevenueCat. For example, when it asks for Bundle ID - which bundle ID do i input? My watch app has 3 bundle IDs for the app, the watch app, watchkit extension. There's no documentation out there, it's very confusing.
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
154 Views

Local notifications with variable text

Hi, I did a watchOS lab today where I asked how to create a local notification (which repeats at a regular interval), but I want to change the text so that that the message is relevant "You currently have x number of words to revise". I have setup the notification in my extension delegate as follows: notificationCenter = UNUserNotificationCenter.current() notificationCenter.removeAllPendingNotificationRequests() let options: UNAuthorizationOptions = [.alert, .sound, .badge] notificationCenter.requestAuthorization(options: options) { (didAllow, error) in if !didAllow { print("User has declined notifications") } } let content = UNMutableNotificationContent() content.title = "Overdue cards" content.body = "You have " + String(wordsOverdue) + " words to revise. " content.sound = UNNotificationSound.default content.userInfo = ["Overdue": database.getWordsOverdue()] The Apple engineer suggested I add the last line as the variable number/content. Then he said to use the NotificationController where there is a didReceive method that is called when a notification comes in, and I can update my notification view. The problem is, didReceive never gets called. When I test my app, it always just sends the original notification that I setup. What do I need to do for notification controller to know when a local notification has come in? I'm open to alternative solutions, since I just have a single value that needs to be updated.
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
346 Views

GeometryReader broken after update

I've downloaded the new Xcode 11.4 update and it's broken my codebase. I use GeometryReader to determine the user's Watch screen size so it can draw a frame that fills up most of the frame.Say if I wrote this to draw a rectangular frame:var body: some View { GeometryReader {geometry in ZStack { // Draw rounded rectangle flashcard background RoundedRectangle(cornerRadius: 15, style: .continuous) .frame(width: geometry.size.width, height: geometry.size.height*0.9) } } }It looks fine at the moment. But my main view usually uses subviews more like this:var body: some View { GeometryReader {geometry in ZStack { // Draw rounded rectangle flashcard background Frontside(id: self.$settings.randomNum, sheet: self.$showingSheet, rotate: self.$fullRotation, invis: self.$showNextCard, col: self.$colour, width: geometry.size.width*0.9, height: geometry.size.height).environmentObject(self.settings) .rotation3DEffect(.degrees(self.showResults ? 180.0 : 0.0), axis: (x: 0.0, y: 1.0, z: 0.0)) .rotation3DEffect(.degrees(self.fullRotation ? 360.0 : 0.0), axis: (x: 0.0, y: 1.0, z: 0.0)) .opacity(self.showResults ? 0 : 1) .zIndex(self.showResults ? 0 : 1) } } }public struct Frontside: View { @EnvironmentObject var settings: UserSettings @Binding public var id: Int @Binding public var sheet: Bool @Binding public var rotate: Bool @Binding public var invis: Bool @Binding public var col: Int public var width: CGFloat public var height: CGFloat public var body: some View { ZStack { // Draw rounded rectangle flashcard background RoundedRectangle(cornerRadius: 15, style: .continuous) .frame(width: self.width, height: self.height) .zIndex(0) } } }For some reason this causes an error when I call Frontside. Does anyone know why? There doesn't seem to be a real difference between the two code snippets other than using a subview in the second example.
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
320 Views

Text alignment in an actionsheet

.actionSheet(isPresented: $showingExampleSentences) { ActionSheet(title: Text("Example Sentence"), message: Text(sentence_foreign_language + "\n" + .sentence_english), buttons: [.default(Text("OK"))]); }I've got a SwiftUI action sheet where it displays two lines of text, but by default they are centre-aligned. Is there a way to make it aligned to the top-left?
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
169 Views

Watch app works fine in Simulator but crashes on Watch

My app crashes as soon as I try to launch it from my Watch, even though it works completely fine in various simulators. How do I go about finding out what is causing it to crash?Note that I've had my app run on my watch before, but all the iOS/WatchOS/Catalina updates as late caused an issue where I couldn't install my app to my Watch. After the latest update I can still it to my watch again except it just crashes on startup.
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
310 Views

Quickest way to create an icon set?

I have just designed an icon in Sketch for a Watch app. In Xcode, it looks like I need to create 11 different sizes of this icon. What is the quickest way to do this? Is there an app/script that can import the icon I've created and creates the 11 different-sized icons? Thanks.
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
593 Views

How to create a time picker?

import SwiftUI struct NotificationSettings: View { @State private var dailyReminder = false var body: some View { VStack { Toggle(isOn: $dailyReminder) { Text("Daily reminder") } Spacer() } .navigationBarTitle(Text(verbatim: "Notifications")) } }After toggling daily reminder, I'd like to create a time picker for the user to select when the daily reminder/notification will occur. I thought something like DatePicker would suit my needs but then it said it is not supported in WatchOS. So what other alternatives are available? Thanks.
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
408 Views

How to save settings selections

import SwiftUI struct CardTheme: View { @State private var theme = globalVarTheme var body: some View { List { HStack { Text("Mono") .onTapGesture { self.setTheme(i: 0) } Spacer() if(theme == 0) { Image(systemName: "checkmark") .foregroundColor(Color.green) } } HStack { Text("Cool") .onTapGesture { self.setTheme(i: 1) } Spacer() if(theme == 1) { Image(systemName: "checkmark") .foregroundColor(Color.green) } } HStack { Text("Cute") .onTapGesture { self.setTheme(i: 2) } Spacer() if(theme == 2) { Image(systemName: "checkmark") .foregroundColor(Color.green) } } } .navigationBarTitle(Text(verbatim: "Card Order")) } func setTheme(i: Int) { theme = i } }I have a settings menu where the user picks a theme, the default value is set to a global variable, globalVarTheme, which is 0. But after they make a selection, exit that menu, and re-enter the menu it goes back to 0 (the first item) even if they have chosen one of the other items. How do I save their selection?Also, what is the best way to save user selections beyond the current app session? Should I write all their selections to a plist file or is there a conventional way?
Asked
by dshum17.
Last updated
.
Post not yet marked as solved
566 Views

How do I create this type of list?

On the Apple Watch, if you go to Settings -&gt; Wake Screen and then scroll down to ON SCREEN RAISE SHOW LAST APP. Underneath it is a list/table where the items are grouped, the first and last items have a rounded rectangle whereas the items in the middle are just rectangles. I would like to use this UI element as well when I present the user a list that functions like a radio button list. Do you know what this UI element is called? Is it just a List but with a specific list style? Thanks.
Asked
by dshum17.
Last updated
.