Post

Replies

Boosts

Views

Activity

Using and expressing "case let" statements
After seveal years with Swift, I still find it hard to use the if case let or while case let, even worse with opotional pattern if case let x?.So, I would like to find an expression to "speak" case let more naturally.Presently, to be sure of what I do, I have to menatlly replace the if case by the full switch statement, with a single case and default ; pretty tedious.I thought of canMatch or canMatchUnwrap … with:So, following would readif case let x = y { // if canMatch x with yif case let x? = someOptional { // if canMatchUnwrap x with someOptionalwhile case let next? = node.next { // while canMatchUnwrap next with node.nextAm I the only one with such problem ? Have you found a better way ?
5
0
7.7k
Jun ’21
Getting back from Splitview
In this app, I have: a VC as entry point (root) which segues (push) to a SplitViewController On iPad, when I get into the splitView, I can get back to the root by dragging down the split view. But on iPhone, this does not work: even though presentation is .automatic, Splitview covers all screen. No way to get back. I tried to create a back button in the detail views… Could not get it. What is the best way to do this ? is there a setup for the initial segue or the views presentation modes to allow pop back ? can I add a back button ? Where, calling what action to return ? I cannot embed splitViewController in nav stack … I would like to have the same solution on both iPhone and iPad…
1
0
625
Jun ’21
Height of safe area margin in iPhone 12 Pro Max
I have an image to fill the entire screen, even behind the notch. So I set the Top margin to safe area to -44. That works OH on all iPhones… except on iPhone 12 ProMax simulator. Here I get a few pixels uncovered at top. I had to change value to -48 to get everything OK. So question is: has "notch area" which defines safe area increased 4 pixels on iPhone 12 Pro max ? If so, is it a hardware change ?
1
0
4k
Jun ’21
Assignment operator in Swift - What is the rationale behind language design ?
I suspect this point has been discussed in length, but I would like to find some reference to the design logic behind some Swift key aspect : the assignment operator, by value or reference. We know well how = works, depending it deals with reference or value (knowing the consequence of misuse) and the difference between the 2 : class AClass { var val: Int = 0 } struct AStruct { var val : Int = 0 } let aClass = AClass() let bClass = aClass bClass.val += 10 print("aClass.val", aClass.val, "bClass.val", bClass.val) let aStruct = AStruct() var bStruct = aStruct bStruct.val += 10 print("aStruct.val", aStruct.val, "bStruct.val", bStruct.val) Hence my question. Was it ever considered to have 2 operators, one used to assign reference and the other to assign value? Imagine we have : = operator when dealing with references := operator when dealing with content. Then let bClass = aClass would remain unchanged. But var bStruct = aStruct would not be valid anymore, with a compiler warning to replace by var bStruct := aStruct On the other end, we could now write let bClass := aClass to create a new instance and assign another instance content, equivalent to convenience initialiser class AClass { var val: Int = 0 init(with aVar: AClass) { self.val = aVar.val } init() { } } called as let cClass = AClass(with: aClass) But the 2 operators would have made it clear that when using = we copy the reference. When using := we copy content. I do think there is a strong rationale behind the present design choice (side effects I do not see ?), but I would appreciate to better understand which.
2
0
751
Jun ’21
Sandbox - security scoped URL - MacOS
In a MacOS App: When I create a file (in a folder), I save a security bookmark for the file. if I ask user to authorise its folder (before creating the file in it), I can save its bookmark too, allowing to create other files in this folder. So, when I create a file and need to create a companion (eg, a Results file), I first ask access to the folder, then create the file and create the results file in the same folder (hence having sandbox authorisation). My understanding is that it is not possible to programmatically create and save the folder bookmark, after deriving its url from the file url, without requesting user to explicitly grant access (with NSOpen panel) ? Which would be very logical as it would deny the goal of security bookmarks. So, is user explicit authorisation required (logical but creates more complexity when user moves files in the Finder). Note: In fact don't really need it, as I save bookmark for every accessed file, but I would like to know.
1
0
802
Apr ’21
Distribution of MacApp outside of Appstore for a demo version
I consider the following distribution scheme for some Mac App: distribute the commercial (paying) version on Appstore propose a free demo version (of course limited in some aspects) on a web site. This would of course be notarised. The reason is to avoid having several versions on the Appstore which could create some confusion. The 2 versions would have similar names and differ essentially in the size of data they can handle. Does anyone know if this is authorised by the Appstore Guidelines ? Or must I publish both on the AppStore ? Is there a risk my app being rejected as spam ?
1
0
592
Apr ’21
Passing data from an App VC to its widget
Learning Widgets, I try a simple pattern: get a textField in the app; have the Widget updated when textField is changed. App is UIKit. Widget has No "included Configuration Intent". It compiles and works. Widget is updated every 5 minutes as asked line 23 (final snippet). But the message is never updated (line 48 of final snippet) with globalToPass (as expected from line 24): it always shows "Hello". What I tried: Create a singleton to hold the data to pass: class Util { &#9;&#9; &#9;&#9;class var shared : Util { &#9;&#9;&#9;&#9;struct Singleton { &#9;&#9;&#9;&#9;&#9;&#9;static let instance = Util() &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;return Singleton.instance; &#9;&#9;} &#9;&#9; &#9;&#9;var globalToPass = "Hello" } shared the file between the 2 targets App and WidgetExtension In VC, update the singleton when textField is changed and ask for widget to reload timeline &#9;&#9;@IBAction func updateMessage(_ sender: UITextField) { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;Util.shared.globalToPass = valueToPassLabel.text ?? "--" &#9;&#9;&#9;&#9;WidgetCenter.shared.reloadTimelines(ofKind: "WidgetForTest") &#9;&#9;&#9;&#9;WidgetCenter.shared.reloadAllTimelines() &#9;&#9;} Problem : Widget never updated its message field Probably I need to have the message in @State var, but I could not get it work. Here is the full widget code at this time: import WidgetKit import SwiftUI struct LoadStatusProvider: TimelineProvider { &#9;&#9; &#9;&#9;func placeholder(in context: Context) -> SimpleEntry { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;SimpleEntry(date: Date(), loadEntry: 0, message: Util.shared.globalToPass) &#9;&#9;} &#9;&#9;func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;let entry = SimpleEntry(date: Date(), loadEntry: 0, message: Util.shared.globalToPass) &#9;&#9;&#9;&#9;completion(entry) &#9;&#9;} &#9;&#9;func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { &#9;&#9;&#9;&#9;var entries: [SimpleEntry] = [] &#9;&#9;&#9;&#9;// Generate a timeline consisting of five entries an hour apart, starting from the current date. &#9;&#9;&#9;&#9;let currentDate = Date() &#9;&#9;&#9;&#9;for minuteOffset in 0 ..< 2 { &#9;&#9;&#9;&#9;&#9;&#9;let entryDate = Calendar.current.date(byAdding: .minute, value: 5*minuteOffset, to: currentDate)! &#9;&#9;&#9;&#9;&#9;&#9;let entry = SimpleEntry(date: entryDate, loadEntry: minuteOffset, message: Util.shared.globalToPass) &#9;&#9;&#9;&#9;&#9;&#9;entries.append(entry) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;let timeline = Timeline(entries: entries, policy: .atEnd) &#9;&#9;&#9;&#9;completion(timeline) &#9;&#9;} } struct SimpleEntry: TimelineEntry { &#9;&#9;let date: Date &#9;&#9;let loadEntry: Int &#9;&#9;let message: String } struct WidgetForTestNoIntentEntryView : View { &#9;&#9;var entry: LoadStatusProvider.Entry &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;let formatter = DateFormatter() &#9;&#9;&#9;&#9;formatter.timeStyle = .medium &#9;&#9;&#9;&#9;let dateString = formatter.string(from: entry.date) &#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(String(entry.message)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Started") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(entry.date, style: .time) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Now") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(dateString) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Loaded") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(String(entry.loadEntry)) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;} } @main struct WidgetForTestNoIntent: Widget { &#9;&#9;let kind: String = "WidgetForTestNoIntent" &#9;&#9;var body: some WidgetConfiguration { &#9;&#9;&#9;&#9;StaticConfiguration(kind: kind, provider: LoadStatusProvider()) { entry in &#9;&#9;&#9;&#9;&#9;&#9;WidgetForTestNoIntentEntryView(entry: entry) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.configurationDisplayName("My Widget") &#9;&#9;&#9;&#9;.description("This is an example widget.") &#9;&#9;} } struct WidgetForTestNoIntent_Previews: PreviewProvider { &#9;&#9;static var previews: some View { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;WidgetForTestNoIntentEntryView(entry: SimpleEntry(date: Date(), loadEntry: 0, message: "-")) &#9;&#9;&#9;&#9;&#9;&#9;.previewContext(WidgetPreviewContext(family: .systemSmall)) &#9;&#9;} } I have not defined extension for IntentHandler
2
0
2.3k
Mar ’21
Update to Catalina, not to Big Sur
One of my production Mac is still on Mojave. I want to update to Catalina and not Big Sur (waiting for dust to settle down). Automatic update from system preferences only proposes Big Sur as well as some patch updates for MacOS 10.14.6 What is the safe and sure way to update from Mojave to the latest Catalina ?
3
0
6.1k
Mar ’21
What is MGIsDeviceOneOfType
Just installed XCode 10.I receive the following warning:2018-06-05 13:25:47.686865+0200 simpleTest[14581:1428592] libMobileGestalt MobileGestalt.c:875: MGIsDeviceOneOfType is not supported on this platform.Cannot find what MGIsDeviceOneOfType is about.Edited : is it related to Mapping and Geographical Information System (“MGIS”) ?
18
0
46k
Mar ’21
Uppercased words are not spoken correctly
Using AVSpeechSynthesizer, I noticed that some works in UPPERCASe are not correctly spoken. SMALL is pronounced small but WIDTH is pronounced W-I-D-T-H I reproduced the problem in playground: let sentence = "Hello everyone. Two minutes to go. SMALL WIDTH." let synthesizer = AVSpeechSynthesizer() let utterance = AVSpeechUtterance(string: sentence) utterance.voice = AVSpeechSynthesisVoice( &amp;#9;language: "en-GB" ) utterance.rate = AVSpeechUtteranceDefaultSpeechRate * 1.05 synthesizer.speak(utterance) Is it the expected behaviour ?
1
0
1.2k
Mar ’21
Is the new forum better ?
The new forum has been there for a week now. I did wait to get accustomed to it so that my comments are not just due to the change factor. I think it is now possible to make some assessment and I would appreciate others’ opinion to see if it is just me… There are some good points: the editor is much less whimsical the possibility to tag topic is a good thing search has improved (a little). But I find really frustrating points: Editor is better and has a live Preview. What a strange concept in the world of the inventor of WYSIWYG ! Did we return to the 90’s editors with their control characters ? Tags are good, but IMHO it would be useful to have major and minor tags. That would help focus when we list threads by tag by making it possible to select only the major one All posts are now reviewed to avoid spam. Good enough. But why can it take hours (in a case, already 5 hours and still in review) for a very simple answer post (no URL, no bizarre word) to be reviewed. A bit frustrating. And that does not allow for any rapidly going discussion. Many features seem to be inspired from SO, but without some critical capabilities, as the inclusion of images. The concept of upvote or downvote has been introduced as well. Was it really needed ? Won’t it lead to some regrettable side effects that we see in SO where some do not dare propose an answer or even ask a question for fear of a negative vote ? That’s particularly the case for anyone not very fluent in english who may not express properly his/her opinion. I did find that previous developers forum was a more welcoming place than SO. Hope that will not change. There are also capabilities that are missing from previous forum (unless they are so well hidden I could not find them): because of increased spacing, there are now just 15 instead 25 posts per page. And you have to scroll a lot more to get at the end of the shorter list. That do slow down the screening. how can one see the threads he contributed to ? Seems we can only filter the one we authored. It seems now quasi impossible to edit a post, and of course delete it. So at the end, instead of the whaooh effect I was expecting I have just a mixed feeling.
16
0
3.0k
Mar ’21
NSLayoutConstraint should not be declared weak in Xcode 10ß2 - Swift 4.2
When compiling this OSX App in XCode 10 beta 2 (Swift 4.2), I get a warning that did not show in XCode 9.4 each time I create an NSConstraint programmaticallyInstance will be immediately deallocated because property 'myConstraint' is 'weak'fileprivate weak var myConstraint : NSLayoutConstraint! myConstraint = NSLayoutConstraint(item: aButton, attribute: .top, relatedBy: .equal, toItem: aView, attribute: .bottom, multiplier: 1.0, constant: 30)However, there is no such warning for IBOutlet@IBOutlet fileprivate weak var anotherConstraint : NSLayoutConstraint!Is it a just a new warning for an error that existed before ? Or did something change in NSConstraint ?Should I treat IBOutlet and programmatically created differently with respect to weak ?
2
0
5.4k
Feb ’21
Localization and tap gesture
In this app I have a view with 3 textFields or labels on which I have gesture recogniqzers.They work OK.I have localized the app for 2 more languages, and now, when I switxh language (inside the app), I get the following error:2018-02-16 00:19:34.951810+0100 Autonomie[1635:1007703] [Warning] WARNING: A Gesture recognizer (&lt;UITapGestureRecognizer: 0x1757fd90; state = Possible; view = &lt;UITextView 0x17b86600&gt;; target= &lt;(action=autonomieVersionViewTapped:, target=&lt;Autonomie.StartViewController 0x1757f890&gt;)&gt;&gt;) was setup in a storyboard/xib to be added to more than one view (-&gt;&lt;UITextView: 0x17ba8000; frame = (60.5 50; 198 25); text = 'version 0.5 © AlphaNums 2...'; clipsToBounds = YES; hidden = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = &lt;NSArray: 0x175e25d0&gt;; layer = &lt;CALayer: 0x175da320&gt;; contentOffset: {0, 0}; contentSize: {198, 31}&gt;) at a time, this was never allowed, and is now enforced. Beginning with iOS 9.0 it will be put in the first view it is loaded into.&lt;UIButtonLabel: 0x176d3da0; frame = (160 18; 0 0); text = 'Calcular el rango …'; opaque = NO; userInteractionEnabled = NO; layer = &lt;_UILabelLayer: 0x176d01c0&gt;&gt;&lt;UIButtonLabel: 0x1765cc40; frame = (160 18; 0 0); text = 'Calculer autonomie …'; opaque = NO; userInteractionEnabled = NO; layer = &lt;_UILabelLayer: 0x1765cda0&gt;&gt;And gestures do not work.If I switch back to the original language, everything OK.
2
0
3.5k
Feb ’21