Post

Replies

Boosts

Views

Activity

Reply to Running FileManager.default.enumerator on different tasks
Any ideas why this is happening? I was under the impression FileManager was thread safe? Generally, FileManager is considered to be thread safe, but you should better not expect that is declaring FileManager solves all the issues about concurrency. In fact, there's a description: FileManager Threading Considerations The methods of the shared FileManager object can be called from multiple threads safely. However, if you use a delegate to receive notifications about the status of move, copy, remove, and link operations, you should create a unique instance of the file manager object, assign your delegate to that object, and use that file manager to initiate your operations. I guess there may be other cases you should create a unique instance of the file manager object in addition to delegate cases. Can you try using a unique instance of FileManager instead of FileManager.default and tell us what happens?
Topic: App & System Services SubTopic: General Tags:
Nov ’21
Reply to Swift switch statement optimization
Al already noted, semantically switch-cases are evaluated from top to bottom. With a switch statement on an enum with a large (over 100) number of cases would it make sense to replace the switch with a dictionary of closures? That depends on your enum. As far as I checked switch on simple enum cases like: switch value { case .case001: break case .case002: break case .case003: break ... case .case100: break } It is optimized into a simple multiway branching as found in C-switch statement, even in optimization level -Onone. SwitchCaseOptimization`MyClass.switchMethod(_:): 0x100006750 <+0>: pushq %rbp 0x100006751 <+1>: movq %rsp, %rbp 0x100006754 <+4>: movb %dil, %al 0x100006757 <+7>: movb $0x0, -0x8(%rbp) 0x10000675b <+11>: movq $0x0, -0x10(%rbp) 0x100006763 <+19>: movb %al, -0x8(%rbp) 0x100006766 <+22>: movq %r13, -0x10(%rbp) -> 0x10000676a <+26>: movzbl %al, %eax 0x10000676d <+29>: movq %rax, -0x18(%rbp) 0x100006771 <+33>: movq -0x18(%rbp), %rax 0x100006775 <+37>: leaq 0x144(%rip), %rcx ; SwitchCaseOptimization.MyClass.switchMethod(SwitchCaseOptimization.MyCases) -> () + 368 0x10000677c <+44>: movslq (%rcx,%rax,4), %rax 0x100006780 <+48>: addq %rcx, %rax 0x100006783 <+51>: jmpq *%rax (Please be careful, too strong optimization like -O would make whole switch statement into nop, in a simplified all break example as shown above.) I do expect this optimization would occur in Simple enum cases, no rawValue Enum cases with Int as rawValue, the value range is not huge I have not tried with enums with some cases having associated values or enum cases with String as rawValue. (Seems internal case representation is a small int even when its rawValues are String.) So, can you show the definition of your enum?
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Getting started with creating swift playground
Swift Playground on macOS. Thanks for clarifying. (But Swift Playgrounds might be the right name of it.) Start Swift Playgrounds. Click See All beside More Playgrounds. And then click See All beside Starting Points. And then you can choose any of the templates to start with. (https://support.apple.com/en-mo/guide/playgrounds/itc2207c0869/mac) I could not find a good tutorial using the Blank template, please share your experience when you find some.
Nov ’21
Reply to Pass swift func result to func
First of all, you should better not put the parameter declarations directly ahead of some statement in a closure: Amplify.API.get(request: request) {result in switch result { case .success(let data): // Do success stuff case .failure(let apiError): // Do failure stuff } } And you will see you can do it in the same way: Amplify.API.get(request: request) {result in myFunction(result, myParam1, myParam2) }
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Axie Infinity
The dev forum is not a place for notification of release dates of some specific app. Find the site of the developer of the app.
Nov ’21