Posts

Post not yet marked as solved
1 Replies
2.6k Views
I have been doing some tests with the code to DownSampling / Scaling Image an Image from WWDC18 Session 416 iOS Memory Deep Dive.In this session they said that: - "Memory use if related the DIMENSION of the image, NOT file size.” - UIImage is expensive for sizing and resizing (will decompress memory first, internal coordinate space transforms are expensive) - Use ImageIO, it will work with out dirty memory (also API is faster)For my tests I used High Resolution Images with dimensions:1920 × 1080, 2560 × 1600, 3840 × 2160, 2560 × 1600, 4712 × 3133, 2560 × 1600 and 3072 × 2048.The following is the code that I used.import UIKit struct ImageConverter{ static func resize(image: UIImage)-> UIImage{ let size = CGSize(width: 300, height: 300) let renderer = UIGraphicsImageRenderer(size: size) let resizedImage = renderer.image { context in image.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) } return resizedImage } }import UIKit import ImageIO struct ImageIOConverter{ static func resize(url: URL)-> UIImage{ guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil) else { fatalError("Can not get imageSource") } let options: [NSString: Any] = [ kCGImageSourceThumbnailMaxPixelSize: 300, kCGImageSourceCreateThumbnailFromImageAlways: true ] guard let scaledImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options as CFDictionary) else { fatalError("Can not get scaledImage") } return UIImage(cgImage: scaledImage) } }import UIKit class ViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! // Constraints Width: 300, Height: 300 let resource = "1" let ext = ".jpg" var imageNamed : String { return resource + ext } @IBAction func uploadOriginalImage(_ sender: Any) { guard let image = UIImage(named: imageNamed) else { fatalError("Can not get image") } imageView.image = image } @IBAction func uploadImageScaledUsingUIImage(_ sender: Any) { guard let image = UIImage(named: imageNamed) else { fatalError("Can not get image") } imageView.image = ImageConverter.resize(image: image) } @IBAction func uploadImageUsingImageIO(_ sender: Any) { guard let url = Bundle.main.url(forResource:resource, withExtension: ext) else { fatalError("Can not get image url") } imageView.image = ImageIOConverter.resize(url: url) } }Effectively, I found that with ImageIO, the amount of memory is smaller, but at the same time I also noticed that using ImageIO the final image look to have lower quality than using UIImage.I mean, using UIImage the final image looks more to the original image than using ImageIO.I wonder if, Is this the expected result? (Lower image quality but also lower memory).
Posted
by ManuelMB.
Last updated
.
Post not yet marked as solved
0 Replies
616 Views
I have a simple ViewController with a WKWebView, the page renders ok and there is no problem at first. This is the code: import WebKit class SignIWkWebViewViewController: UIViewController {      var wkWebView: WKWebView!    override func loadView() {      let webConfiguration = WKWebViewConfiguration()      wkWebView = WKWebView(frame: .zero, configuration: webConfiguration)      view = wkWebView    }      override func viewDidLoad() {      super.viewDidLoad()      startLoad()    }        // Receive Transfer Details and Results with a Delegate    private lazy var session: URLSession = {      let configuration = URLSessionConfiguration.default      configuration.waitsForConnectivity = true      return URLSession(configuration: configuration, delegate: self, delegateQueue: nil)    }()        var receivedData: Data?        private func startLoad(){      print("\(type(of: self)) \(#function)")            guard let url = URL(string:"https://itunesconnect.apple.com/login") else { fatalError("Can not get url") }            receivedData = Data()      let task = session.dataTask(with: url)      task.resume()    }        private func handleClientError(_ error: Error){      print("Error: \(error)")    } }     extension SignIWkWebViewViewController : URLSessionDataDelegate{  func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {     print("\(type(of: self)) \(#function)")      guard let response = response as? HTTPURLResponse,        (200...299).contains(response.statusCode),        let mimeType = response.mimeType,        mimeType == "text/html" else {        completionHandler(.cancel)        return      }      completionHandler(.allow)    }    func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {      print("\(type(of: self)) \(#function)")      self.receivedData?.append(data)    }    func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {       print("\(type(of: self)) \(#function)")      DispatchQueue.main.async {        //self.loadButton.isEnabled = true        if let error = error {          self.handleClientError(error)        } else if let receivedData = self.receivedData,          let string = String(data: receivedData, encoding: .utf8) {          self.wkWebView.loadHTMLString(string, baseURL: task.currentRequest?.url)        }      }    } } The issue start when I tap in the form field in the web page. I set a breakpoint for UIViewAlertForUnsatisfiableConstraints expr -l objc++ -O -- [[UIWindow keyWindow] autolayoutTrace] And I got this error: UIWindow:0x7f9ed2d05d40 |  UITransitionView:0x7f9ed2c110f0 |  |  UIDropShadowView:0x7f9ed2e071c0 |  |  |  WKWebView:0x7f9ed3027e00'iTunes Connect' |  |  |  |  WKScrollView:0x7f9ed3827800 |  |  |  |  |  WKContentView:0x7f9ed382f800 |  |  |  |  |  |  UIView:0x7f9ed2c0a240 |  |  |  |  |  |  |  UIView:0x7f9ed2c067a0 |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2d13760 |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed501d6c0 |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed500cfd0 |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed50063c0 |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed501d830 |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c18210 |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c107a0 |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKChildScrollView:0x7f9ed3081200 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c14a30 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c19810 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c10910 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c17dc0 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c19560 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  UIScrollViewScrollIndicator:0x7f9ed500f3f0 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  UIView:0x7f9ed500f590 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  UIScrollViewScrollIndicator:0x7f9ed5019150 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  UIView:0x7f9ed50177d0 |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c0fd20 |  |  |  |  |  |  UILayerHostView:0x7f9ed2d09100 |  |  |  |  |  UIView:0x7f9ed5007fd0 |  |  |  |  |  |  UITextSelectionView:0x7f9ed501bbd0 |  |  |  |  |  |  UIHighlightView:0x7f9ed2e0b7f0 |  |  |  |  |  UIScrollViewScrollIndicator:0x7f9ed2e0ad40 |  |  |  |  |  |  UIView:0x7f9ed2e0b680 |  |  |  |  |  _UIScrollViewScrollIndicator:0x7f9ed2e0bb30 |  |  |  |  |  |  UIView:0x7f9ed2e0bcd0 Legend:- is laid out with auto layout + - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES • - layout engine host What is wrong in the code?
Posted
by ManuelMB.
Last updated
.
Post not yet marked as solved
1 Replies
345 Views
In https://appstoreconnect.apple.com I found the following message: The updated Apple Developer Program License Agreement needs to be reviewed The updated Apple Developer Program License Agreement needs to be reviewed. In order to update your existing apps and submit new apps to the App Store, the Account Holder must review and accept the updated agreement by signing in to their account on the Apple Developer website. I went to: https://developer.apple.com/account But I can not find the updated Apple Developer Program License Agreement needs to be reviewed. In: https://developer.apple.com/account/#/membership/XXXXXXXXX (XXXXXXXXX) is my account ID at the bottom I can see Agreements (2), but If I click in any of then it just download a pdf file. Where I need to go to accept it?
Posted
by ManuelMB.
Last updated
.
Post not yet marked as solved
2 Replies
2.4k Views
Hello,I have a big problem, when I try to go to settings in the simulators, the screen goes sometimes to white and sometimes to black, but returns to the Home Screen, sometimes even it restart my Mac.I tried to uninstall all simulators, install again Xcode, but the issue is not solve.I also tried Reset NVRAM or PRAM on Mac.Before to ask here in the forum, I tried to go to Support > Contact us > Development and technical issues > Xcodehttps://developer.apple.com/contact/#!/topic/SC1102/subtopic/30019/solution/selectBut there is no option there to submit the selection and no way to continue further, I tried in 3 different web browsers.Please help me, I have wasted 3 days trying to solve this problem.
Posted
by ManuelMB.
Last updated
.
Post marked as solved
2 Replies
353 Views
I am having issues with renewing subscriptions.From Session 705 Engineering Subscriptions WWDC 2018 - Does the User Have an Active Subscription?, I know that the way to answer to these questions is: - Filter transactions by original_transaction_id - Find transaction with the latest expires_date - Date in past shows user is not subscribed Subscription Period ---------------------------------------------------------> Time ---> USER HAS NO AN Active Subscription expires_date Today Subscription Period ---------------------------------------------------------> Time ---> USER HAS AN Active Subscription Today expires_date But I get the following data: 6 elements ▿ 0 : InApp ▿ expiresDate : 2020-05-02 21:31:29 +0000 ▿ 1 : InApp ▿ expiresDate : 2020-05-02 21:36:29 +0000 ▿ 2 : InApp ▿ expiresDate : 2020-05-02 21:41:29 +0000 ▿ 3 : InApp ▿ expiresDate : 2020-05-02 21:46:29 +0000 ▿ 4 : InApp ▿ expiresDate : 2020-05-02 21:51:51 +0000 ▿ 5 : InApp ▿ expiresDate : 2020-05-02 21:56:51 +0000 <====== transaction with the latest expires_datelet today = Date()2020-05-03 21:48:29 +0000Transaction with the latest expires_date is before Today.Why is this happening?
Posted
by ManuelMB.
Last updated
.
Post not yet marked as solved
0 Replies
1.8k Views
In WWDC 2019 session In-App Purchases and Using Server-to-Server Notifications they say that in our server we must have in a database a field for the userId.I think that a good candidate to use as userId for iOS and tvOS would be identifierForVendor:UIDevice.current.identifierForVendor?.uuidStringAnd for macOS the GUID but the info that I found in the Apple documentation uses Objective-C instead of Swift:https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW14Is there info about who to do it using Swift somewhere or should I use Objective-C?I also found some code of Swift in github, but I do not now if really get the real Mac UUID and also if this method is allowed by Apple. func macSerialNumber() -> String { let platformExpert: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); guard let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformSerialNumberKey as CFString, kCFAllocatorDefault, 0) else { fatalError("Can not get serialNumberAsCFString") } IOObjectRelease(platformExpert); return (serialNumberAsCFString.takeUnretainedValue() as? String) ?? "" } func applicationDidFinishLaunching(_ aNotification: Notification) { print("Unique Device Identifier: \(macSerialNumber())") }
Posted
by ManuelMB.
Last updated
.
Post marked as solved
1 Replies
728 Views
In a UIViewcontroller I set:navigationController?.navigationBar.barTintColor = .blackI would like to change the default appearance of the following:Carrier name and its signal strength, wifi strength or (3G, 4G or 5G), clock time, battery level and network activity indicator when is visible.Because with a black navigationBar barTintColor these are indistinguishable.How could I do it?
Posted
by ManuelMB.
Last updated
.
Post marked as solved
5 Replies
1.5k Views
I am trying to add a monthly auto renewable subscription to my app.I do not understad why the following happens:I just create a new sandbox tester and add it to my iPhone device in settings > iTunes & App Store > Sandbox AccountI delete the app from the device and in XCode I do Product > Clean & build folder and then install the app in the device.When the app is launched I start observing the Payment Queue by adding:SKPaymentQueue.default().add(self)Then the following function is called:func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])At this point in the debug console:(lldb) po transactions.count return 9(lldb) po transactions[0].payment.productIdentifierreturn the product identifier of my monthly auto renewable subscriptionAnd the SKPaymentTransactionState of the transaction is purchased before I buy a subscription with this new sandbox user.Why is this happening?Is there any way to remove for all sandbox users all previous purchases?
Posted
by ManuelMB.
Last updated
.
Post marked as solved
6 Replies
1.7k Views
After update a project to Swift 4.2 I got this error message:'dismissViewController' has been renamed to 'dismiss(_:)'So I changed the code from:dismissViewController(shareOptionsViewController)to:dismiss(shareOptionsViewController)But the controller do not dismiss.I am using Storyboards and using a segue of kind Sheet.Before update to Swift 4.2, it works ok.What is wrong in the above code?
Posted
by ManuelMB.
Last updated
.
Post marked as solved
8 Replies
6.6k Views
I am trying to migrate an existing project from Swift 4 to Swift 4.2, and don´t know how to modify some piece of the code.I have the following class to keep track of the different CKRecordZone names and their CKServerChangeTokens.import Foundation import CloudKit class CloudKitFetchChangeToken{ private var dictionaryFetchChangeToken : [String : CKServerChangeToken]?{ get { guard let defaults = UserDefaults(suiteName: "group.com.company.AppName") else { fatalError("Can not get UserDefaults for suiteName" ) } guard let tokenData = defaults.dictionaryFetchChangeToken else { return nil } // Using SWIFT 4 // Warning SWIFT 4.2: 'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead return NSKeyedUnarchiver.unarchiveObject(with: tokenData) as? [String : CKServerChangeToken] } set { guard let newValue = newValue else { guard let defaults = UserDefaults(suiteName: "group.com.company.AppName") else { fatalError("Can not get UserDefaults for suiteName" ) } defaults.dictionaryFetchChangeToken = nil return } // Using SWIFT 4 //let data = NSKeyedArchiver.archivedData(withRootObject: newValue) // Using SWIFT 4.2 let coder = NSKeyedArchiver(requiringSecureCoding: true) coder.encode(newValue, forKey: NSKeyedArchiveRootObjectKey) let data = coder.encodedData guard let defaults = UserDefaults(suiteName: "group.com.company.AppName") else { fatalError("Can not get UserDefaults for suiteName" ) } defaults.dictionaryFetchChangeToken = data } } private let queue = DispatchQueue(label: "com.AppName.CloudKitFetchChangeToken.queue") public subscript(key: String) -> CKServerChangeToken? { get { return queue.sync { return dictionaryFetchChangeToken?[key] } } set(newValue) { queue.sync { dictionaryFetchChangeToken?[key] = newValue } } } var isEmpty: Bool { return dictionaryFetchChangeToken?.count == 0 } var existStorage : Bool{ return dictionaryFetchChangeToken != nil } func createSorage(){ dictionaryFetchChangeToken = [:] } }My problem is with var dictionaryFetchChangeToken, I think I managed ok the change of the sintax from Swift 4 to Swift 4.2 in the set (), butI don´t know how to do it in the get() part of the code.Warning SWIFT 4.2: 'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead.In Swift Dictionary is a Generic Structure, and the previous method is waiting for a class.
Posted
by ManuelMB.
Last updated
.
Post marked as solved
6 Replies
2.7k Views
I had an app that used an UIWebView in iOS 11, and had the following Environmet Variables for debugging networks conections.Product > Sceheme > Edit Scheme > Environmet Variables > CFNETWORK_DIAGNOSTICS 3In iOS 12, UIWebView is deprecated so I changed it for an WKWebView.Now, I can't see any logs in the console about the networks conections.Is it CFNetwork Diagnostic still available in iOS12?
Posted
by ManuelMB.
Last updated
.
Post not yet marked as solved
1 Replies
701 Views
I have the following code:import Cocoa import CloudKit class ViewController: NSViewController { var shareOptionsSettingsForUser : NSSharingService.CloudKitOptions! override func viewDidLoad() { super.viewDidLoad() shareOptionsSettingsForUser = NSSharingService.CloudKitOptions.allowPublic print("shareOptionsSettingsForUser.contains(.standard): \(shareOptionsSettingsForUser.contains(.standard))") print("shareOptionsSettingsForUser.contains(.allowPublic): \(shareOptionsSettingsForUser.contains(.allowPublic))") print("shareOptionsSettingsForUser.contains(.allowPrivate): \(shareOptionsSettingsForUser.contains(.allowPrivate))") print("shareOptionsSettingsForUser.contains(.allowReadOnly): \(shareOptionsSettingsForUser.contains(.allowReadOnly))") print("shareOptionsSettingsForUser.contains(.allowReadWrite): \(shareOptionsSettingsForUser.contains(.allowReadWrite))") } }The console output is:shareOptionsSettingsForUser.contains(.standard): trueshareOptionsSettingsForUser.contains(.allowPublic): trueshareOptionsSettingsForUser.contains(.allowPrivate): falseshareOptionsSettingsForUser.contains(.allowReadOnly): falseshareOptionsSettingsForUser.contains(.allowReadWrite): falseCould someone please explain me why shareOptionsSettingsForUser contains .standard?I do not understand why if I set up the var shareOptionsSettingsForUser with a single option .allowPublic, why it also contains .standard
Posted
by ManuelMB.
Last updated
.
Post not yet marked as solved
0 Replies
780 Views
I use iCloud Key-Value Storage to keep the info about if the privateCloudDatabase has been restricted or not.If the user restrict the database: let ubiquitousKeyValueStore = NSUbiquitousKeyValueStore.default ubiquitousKeyValueStore.set(true, forKey: "PrivateCloudDatabaseRestriction") ubiquitousKeyValueStore.synchronize()If the user unrestrict the database: let ubiquitousKeyValueStore = NSUbiquitousKeyValueStore.default ubiquitousKeyValueStore.set(false, forKey: "PrivateCloudDatabaseRestriction") ubiquitousKeyValueStore.synchronize()In other devices for the same user (diferents for the one that enable or disable the restriction) the user is notify using the following code: let ubiquitousKeyValueStore = NSUbiquitousKeyValueStore.default override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.addObserver(forName: NSUbiquitousKeyValueStore.didChangeExternallyNotification, object: ubiquitousKeyValueStore, queue: OperationQueue.main) { (notification) in print("NSUbiquitousKeyValueStore.didChangeExternallyNotification") } }In case that the previous user send a CKShare with write permissions to others users, How can this users by notified if the owner of the privateCloudDatabase enable or disable the restriction?Also it is possible for the owner of the privateCloudDatabase to check at any time the status of the restrictionlet ubiquitousKeyValueStore = NSUbiquitousKeyValueStore.default let privateCloudDatabaseRestriction = ubiquitousKeyValueStore.bool(forKey: "PrivateCloudDatabaseRestriction")How could check an user that accepted a CKShare with Write Permissions the status of the restriction made by the owner of the privateCloudDatabase?
Posted
by ManuelMB.
Last updated
.
Post marked as solved
2 Replies
954 Views
I am following apple docs about "Changing Access Controls on User Data".https://developer.apple.com/documentation/cloudkit/changing_access_controls_on_user_dataIt works ok for privateCloudDatabase, but if I made the changes in the code to use instead publicCloudDatabase or sharedCloudDatabase and also modify the apiPath to use the appropriate database an error is show.In case of using the publicCloudDatabase the error is the following:"serverErrorCode" : "BAD_REQUEST", "reason" : "BadRequestException: endpoint not applicable in the database type 'publicdb'"In case of using the sharedCloudDatabase the error is the following:"serverErrorCode" : "ACCESS_DENIED", "reason" : "private db access disabled for this account"(Please note also that strangely, in the last error message references private db and not shared db)Is it possible to temporarily deactivate or restrict access to the data associated with a user in publicCloudDatabase and sharedCloudDatabase?
Posted
by ManuelMB.
Last updated
.
Post marked as solved
3 Replies
5.4k Views
I have the following data model in CoreData:The relationships childs and parent are between objects of the same Type (Subject).Subject+CoreDataClass.swiftimport Foundation import CoreData @objc(Subject) public class Subject: NSManagedObject { }Subject+CoreDataPropertiesimport Foundation import CoreData extension Subject { @nonobjc public class func fetchRequest() -> NSFetchRequest<Subject> { return NSFetchRequest<Subject>(entityName: "Subject") } @NSManaged public var idauto: NSNumber? @NSManaged public var longdescription: String? @NSManaged public var parentid: NSNumber? @NSManaged public var shortdescription: String? @NSManaged public var title: String? @NSManaged public var childs: NSSet? @NSManaged public var parent: Subject? }I would like to return a Json file from the content of the sqlite database, so I make the Subject class conform to Codable protocol as follow:Subject+CoreDataClass.swiftimport Foundation import CoreData @objc(Subject) public class Subject: NSManagedObject, Codable { enum CodingKeys: String, CodingKey { case title case shortdescription case longdescription case parent } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(title ?? "", forKey: .title) try container.encode(shortdescription ?? "", forKey: .shortdescription) try container.encode(longdescription ?? "", forKey: .longdescription) try container.encode(parent, forKey: .parent) } public required convenience init(from decoder: Decoder) throws { guard let contextUserInfoKey = CodingUserInfoKey.context, let managedObjectContext = decoder.userInfo[contextUserInfoKey] as? NSManagedObjectContext, let entity = NSEntityDescription.entity(forEntityName: "Subject", in: managedObjectContext) else { fatalError("Failed to decode Subject!") } self.init(entity: entity, insertInto: nil) let values = try decoder.container(keyedBy: CodingKeys.self) title = try values.decode(String.self, forKey: .title) shortdescription = try values.decode(String.self, forKey: .shortdescription) longdescription = try values.decode(String.self, forKey: .longdescription) parent = try values.decode(Subject?.self, forKey: .parent) } } extension CodingUserInfoKey { static let context = CodingUserInfoKey(rawValue: "context") }I did not encode the relationship named childs because I get this error:Fatal error: Optional<NSSet> does not conform to Encodable because NSSet does not conform to EncodableTo encode the data in an UIViewController I got this code:import UIKit import CoreData class RootViewController: UIViewController { var managedObjectContext: NSManagedObjectContext! var subjects : [Subject] = [] func executeFetchRequest(completion:@escaping () -> ()){ let fetchRequest: NSFetchRequest<Subject> = Subject.fetchRequest() fetchRequest.predicate = NSPredicate(format: "TRUEPREDICATE") let sortDescriptor = NSSortDescriptor(key: "idauto", ascending: true) fetchRequest.sortDescriptors = [sortDescriptor] fetchRequest.returnsObjectsAsFaults = false managedObjectContext.perform { self.subjects = try! fetchRequest.execute() completion() } } override func viewDidLoad() { super.viewDidLoad() executeFetchRequest(){ [weak self] in guard let strongSelf = self else { return } do{ let documentDirectoryURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) let jsonURL = URL(fileURLWithPath: "subjects", relativeTo: documentDirectoryURL.appendingPathComponent("Subjects")).appendingPathExtension("json") let jsonEncoder = JSONEncoder() jsonEncoder.outputFormatting = .prettyPrinted let jsonData = try jsonEncoder.encode(strongSelf.subjects) try jsonData.write(to: jsonURL) } catch let error as NSError{ print("Error: \(error.description)") } } } }The problem is that I get the following error in the function: public func encode(to encoder: Encoder) throwsThread 1: EXC_BAD_ACCESS (code=2, address=0x16f4c3ea0)If I don't encode the relationship paren,t I get the Json file ok.How could I modify the code to also encode the relationship parent?
Posted
by ManuelMB.
Last updated
.