I'm getting infrequent crashes when I try to show a newly created PDF. The PDF is file based, and shortly after UIGraphicsEndPDFContext its shown.
The crash reports make it appear that the file itself is being mutated after its displayed.
So my question: is the file (self.filePath) absolutely flushed and closed when UIGraphicsEndPDFContext returns?
If not, is there some way to detect when it has finished?
Thanks!
David
`func addPageNumbers() {
let url = URL(fileURLWithPath: filePath)
guard let document = CGPDFDocument(url as CFURL) else { return }
// You have to change the file path otherwise it can cause blank white pages to be drawn.
self.filePath = "\(filePath)-final.pdf"
UIGraphicsBeginPDFContextToFile(filePath, .zero, nil)
let pageCount = document.numberOfPages
for i in 1...pageCount {
...
}
}
UIGraphicsEndPDFContext()
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Have an app that has a half dozen models. We created a new app version with a new model that has an additional property on one entity.
The options for the persistent store:
do {
let options = [
NSMigratePersistentStoresAutomaticallyOption: NSNumber(value: true),
NSInferMappingModelAutomaticallyOption: NSNumber(value: true)
]
let _ = try persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storeURL, options: options)
} catch {
try? FileManager.default.removeItem(at: storeURL) //Erase old sqlite
// Make new persistent store for future saves
let _ = try? persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storeURL, options: nil)
}
Launch this with data from a previous version. A breakpoint in the catch block never triggers so the migration must have worked.
Since I'm in development, what happens if I run a different branch that doesn't have the new model? I assume the catch block is going to trigger—but it doesn't!
Why doesn't it trigger? Does Core Data essentially ignore the new entity property, so all is well?
I was just surprised ...
Have an app in the store - 10K users. Using the same algorithm for years to download objects, convert them to ManagedObjects, then save them in a context.
Been using the exact same Objective-C code for over 5 years - no changes.
We build the app with Xcode 15.1, release it a few weeks ago, then slowly start getting reports of the app won't boot.
Run the app in 15.1, look at memory usage, and it's a flat line up. But the code is littered with autorelease statements. For this download, max memory was 2.3G! No wonder so many users crashing!
[Worked two weekends straight to get this fixed, but why did it happen???]
The last developer told me he added those to reduce memory pressure, and that they worked for him. (Unfortunately no old memory usage graphs).
But look at the attached image - memory usage increments in a straight line - no saw tooth where memory would get released.
Oh, and this is in one runloop on the main thread (don't blame me, I didn't write the original code!):
I'm sorta baffled right now. I am trying to wonder how I might detect a updated SQL Store in an older app.
have a baseline app, and create a SQL-based repository
in an updated app, change the model and verify that you can see the updated model version. Using lightweight migration
re-run the older app (which will inherit the newer SQL repository).
YIKES - no error when creating the NSPersistenStoreCoordinator!
Nothing in the metadata to imply the store is newer than the model:
[_persistentStoreCoordinator metadataForPersistentStore:store]
My question: is there any way to detect this condition?
David
Note that AsyncDNSResolver is a fairly new Apple sponsored framework (search for it).
I am trying to resolve a hostname (behind a CNAME) but cannot. In face even "ping" in mac Terminal can't.
The host I start with is apidev.leaptodigital.com - when I ask for its CNAME:
resolver.queryCNAME(name: "apidev.leaptodigital.com")
I get:
salespro-dev-server-2.eba-uxpxmksr.us-east-1.elasticbeanstalk.com
Great! But nothing I try with that hostname returns an IP address. I tried queryCNAME again, then queryA, then queryAAAA.
Yet I can send http traffic to this host, so its getting resolved somewhere.
Note that nslookup in Terminal finds it just fine.
David
PS: tried older APIs like CFHostStartInfoResolution but they don't return anything either. Did not try getHostName as its use is discouraged.
Topic:
App & System Services
SubTopic:
Networking
In my case there are three interfaces. I had a mental model that I now believe is incorrect.
If any of the 3 interfaces is "satisfied", then I get one message telling me so. I guess if that one interface goes down, then I should get a second message that tells me that (this is hard to test as Xcode keeps disconnecting from my device when I switch to Settings to change things).
in my case, wifi and cellular are both on. I launch the app, get notified that wifi is satisfied, but nothing on cellular.
So my guess is there is a hierarchy: wired, wifi, and cellular. If the highest priority path is available, the others are assumed "off" since you have a path. Thus, you will never get "satisfied" for more than one path.
Correct?
My company wants to be insure that if my Objective-C to Swift conversions fail in anyway, that the app can revert to using the older Objective-C code. By using a remotely controllable flag, the app can switch which code runs as, both are compiled into the app.
Essentially, I create a protocol that describes the original class, then both classes (with a "s" or "o" appended to them) conform to the protocol.
Protocol: Object
Objective-C class: oObject
Swift class: sObject
That said, I hit one issue that I just can't seem reason out. I create a Objective-C function that returns the appropriate class:
Class<Object> classObject(void) {
if (myFlag) {
return [sObject class];
} else {
return [oObject class];
}
}
Swift deals with this really well - I can create an initialized object using:
let object = classObject().init()
but I cannot find a way to do this in Objective-C:
Object *object = [[classSalesForceData() alloc] init];
fails with "No known class method for selector 'alloc'"
Is there a way to do this?
David
PS: my workaround is to return an allocated object:
Object *createObject(void) {
if (myFlag) {
return [sObject alloc];
} else {
return [oObject alloc];
}
}
I searched online didn't find anything.
David
Topic:
Developer Tools & Services
SubTopic:
Xcode
Select the Project in leftmost pane, open right most pane where Project Document is shown.
My (quite old) project has the Project Format set to "Xcode 3.2" (which amazingly I used at one point!).
I changed it to "Xcode 16.3", and even selected "Minimize Project References", closed the project, then re-opened it. However, the size of the "project.pbxproj" file didn't change at all.
I'm told the newer formats reduce project size as well as reduce merge conflicts when new files are added to the project.
Is there a "compress" option from the command line?
Thanks,
David
Topic:
Developer Tools & Services
SubTopic:
Xcode
User is using my app, the goes to System Settings, and changes some of my App's settings (switches, text fields, etc).
Does the system send my app any kind of notification?
David
PS: I tried all kinds of searches on this and found nothing.
Topic:
App & System Services
SubTopic:
Notifications
I didn't really find anything in Apple docs on how to debug my extension using Xcode (so not saying it doesn't exist).
I found a current Stack post on it, with several devs all stuck. In 2024 someone said run the Preview Extension, select Finder as the test app, then in a Finder window select a file of the correct type and tap space.
Nothin happens when I do this (I get the file icon showing).
Suggestions most welcome!