Post not yet marked as solved
When using Task { ... } in Swift 5.5, I'm unclear if retain cycles might be an issue or not. For example:
class ViewController: UIViewController {
private var rows = [String]()
private var tableView: UITableView?
func populateRows() {
Task {
rows = (try? await getRowsFromNetwork()) ?? []
tableView?.reloadData()
}
}
}
Will populateRows retain the view controller for the life of the task because it references rows and tableView?
If the view controller goes out of scope, I'd like it to have the freedom to deallocate without populateRows retaining it. This syntax compiles, but I don't know if it makes sense:
class ViewController: UIViewController {
private var rows = [String]()
private var tableView: UITableView?
func populateRows() {
Task { [weak self] in
self?.rows = (try? await self?.getRowsFromNetwork()) ?? []
self?.tableView?.reloadData()
}
}
}
I don't mind if the task continues to run. (I'm not worried about canceling it.) I just want to understand if there is a way to avoid retaining the view controller in the task, and if that happens automatically or if something like [weak self] is needed.
In Xcode 11 I've created a binary xcframework written Swift. One of the public types that it defines is an enum, and it needs to be usable from Swift and Objecitve-C. So I added the @objc modifier like so:@objc public enum MyEnum: Int {
case aaa
case bbb
}I import the xcframework into a separate Swift project and have the following switch statement:switch myEnum {
case .aaa:
break
case .bbb:
break
}Unfortuntely compiling the switch statement produces this warning:"Switch covers known cases, but 'MyEnum' may have additional unknown values."If I were to define the enum in Objective-C instead of Swift, I would use NS_CLOSED_ENUM to ensure that there are no future cases, which would solve the Swift warning. But I don't know how to make a "closed enum" in Swift. Enums in Swift already are closed, but I think the @objc flag might be canceling that out in the interface.Can this be solved? Thanks in advance.
I'd like to know about the use case where an iOS app depends on Facebook for its core functionality.When running the app, the user cannot proceed unless they sign in with Facebook. Once they sign in, the Facebook SDK is used for a variety of purposes that are core to the app's functionality. Without Facebook, the app has no purpose or usable features.Is Sign In with Apple required in this case?According to https://developer.apple.com/news/?id=06032019j"Sign In with Apple ... will be required as an option for users in apps that support third-party sign-in when it is commercially available later this year."
If I have an ARView, is it possible to add SCNNode instances? I want to use Entity instances for some things and SCNNode instances for others. Ideally I'd like to have an SCNNode as a child of an Entity. I poked around the class hierarchy and I can't find a way.
This code:let d0 = Data(bytes: [10, 11, 12, 13, 14, 15])
print(d0[2])
print(d0[3])
let d1 = d0[2...3]
print(d1.count)
print(d1[0])...produces this output in an Xcode 9.3 / Swift 4.1 playground:12
13
2...and then crashes on the last line:print(d1[0])...with this error:error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).Is this a bug, and if so, any suggestions for a workaround?
When I upgraded from Xcode 8 to 9, existing code that creates a directory started to fail. This code fails on Xcode 9 on a tvOS device. It runs fine in the simulator, and in Xcode 8 it runs fine in the simulator and on a device.It's easy to repro. Create a new tvOS project with Xcode 9 with the following app delegate:@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
var url = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask)[0]
url = url.appendingPathComponent("Testing123", isDirectory: true)
print("URL = \(url)")
print("Exists = \(fileExists(url: url))")
do {
try FileManager.default.createDirectory(at: url,
withIntermediateDirectories: true, attributes: nil)
}
catch {
assertionFailure("Could not create \(url): \(error)")
}
return true
}
private func fileExists(url: URL) -> Bool {
return (try? url.checkResourceIsReachable()) ?? false
}
}Here's the output when running on a device:URL = file:///var/mobile/Containers/Data/Application/1ECA9AED-6A8E-4208-A9B4-220ACE92621B/Library/Testing123/Exists = falsefatal error: Could not create file:///var/mobile/Containers/Data/Application/1ECA9AED-6A8E-4208-A9B4-220ACE92621B/Library/Testing123/: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “Testing123” in the folder “Library”." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/1ECA9AED-6A8E-4208-A9B4-220ACE92621B/Library/Testing123, NSUnderlyingError=0x1c0053800 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}: file /Users/.../AppDelegate.swift, line 30This reproduces with two different tvOS devices, and with two different development teams / app store companies / bundle IDs.Is anyone else having this problem? Any insights would be appreciated, thanks!