Objective-C

RSS for tag

Objective-C is a programming language for writing iOS, iPad OS, and macOS apps.

Posts under Objective-C tag

191 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

NSKeyedUnarchiver decodeObjectOfClasses failed
I tried to read an Object : -(NSMutableDictionary*) readMyObject:(NSData*)data; { NSError * error; Class class = [NSMutableDictionary class]; NSMutableDictionary * dict; dict = [NSKeyedUnarchiver unarchivedObjectOfClass:class fromData:data error:&error]; return dict; the result was nil. I searched by Developer for a solution and found one : { // NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] init]; [unarchiver decodeObjectOfClasses: [[NSSet alloc]initWithArray: @[[NSDictionary class], [NSMutableDictionary class], [NSArray class], [NSMutableArray class], [NSString class], [NSNumber class]]] forKey:NSKeyedArchiveRootObjectKey]; [unarchiver finishDecoding]; } The first line was from me and it crashed the project. I assume there is an easy answer, not for me.🥲 Uwe
6
0
1.3k
May ’24
"zero length data" error
I had a customer feedback about a "zero length data" error which was captured using an exception handler and displayed using NSAlert. My app employs [NSURLSession dataTaskWithURL:] to download XML and image data. But I got no idea what it is about. I assume it's related to NSData, but this error never happened before (for years). Does anyone have any idea about the source of this error?
2
0
653
Feb ’24
Interpreting QuartzCore Sonoma 14.3 crashes
We are getting many crash reports from users that just updated to Sonoma 14.3 on arm64 macs. We can reproduce these types of crashes on arm64 14.3 machines only (not Intel 14.3, other versions of macOS, etc). A typical crash report: Code Type: arm64 Parent Process: launchd [1] Date/Time: 2024-01-27T15:51:54.999Z Launch Time: 2024-01-27T15:51:43Z OS Version: Mac OS X 14.3.0 (23D56) Report Version: 104 Exception Type: SIGILL Exception Codes: ILL_NOOP at 0x2e23fc03 Crashed Thread: 9 Thread 9 Crashed: 0 QuartzCore 0x0000000188923428 CA::OGL::PathRenderer::PathRenderer(CA::OGL::Context&, CA::Mat2 const&, CA::Bounds const&, bool, bool, bool) + 268 1 QuartzCore 0x0000000188922d90 CA::OGL::PathFiller::PathFiller(CA::OGL::Context&, CA::Mat2 const&, CA::Bounds const&, CA::OGL::PathCubic*, int, CA::OGL::PathRect*, int, CA::OGL::PathFiller::ScanlinePoint*, int, bool, bool) + 48 2 QuartzCore 0x000000018885db28 CA::CG::fill_path(CA::CG::Renderer&, CGPath const*, CA::CG::StrokeParameters const*, CA::Rect const*, CA::ScanConverter::FillRule, CA::Mat2 const&, bool) + 2724 3 QuartzCore 0x00000001887ffe7c CA::CG::DrawOp::render(CA::CG::Renderer&) const + 1520 4 QuartzCore 0x00000001887fce5c CA::CG::Queue::render_callback(void*) + 1472 5 libdispatch.dylib 0x0000000180448910 _dispatch_client_callout + 16 6 libdispatch.dylib 0x000000018044ff74 _dispatch_lane_serial_drain + 952 7 libdispatch.dylib 0x00000001804509d4 _dispatch_lane_invoke + 376 8 libdispatch.dylib 0x000000018045b61c _dispatch_root_queue_drain_deferred_wlh + 284 9 libdispatch.dylib 0x000000018045ae90 _dispatch_workloop_worker_thread + 400 10 libsystem_pthread.dylib 0x00000001805f6114 _pthread_wqthread + 284 11 libsystem_pthread.dylib 0x00000001805f4e30 start_wqthread + 4 Thread 0: 0 libsystem_kernel.dylib 0x00000001805bb5a8 kevent_id + 8 1 libdispatch.dylib 0x000000018046bff4 _dispatch_event_loop_wait_for_ownership + 432 2 libdispatch.dylib 0x0000000180457f94 DISPATCH_WAIT_FOR_QUEUE + 336 3 libdispatch.dylib 0x0000000180457b5c _dispatch_sync_f_slow + 144 4 QuartzCore 0x00000001887e36a0 CABackingStoreGetFrontTexture(CABackingStore*, CGColorSpace*) + 184 5 QuartzCore 0x00000001887d374c -[NSObject(CARenderValue) CA_prepareRenderValue] + 228 6 QuartzCore 0x0000000188a2545c CA::Layer::prepare_contents(CALayer*, CA::Transaction*) + 188 7 QuartzCore 0x00000001887d0798 CA::Layer::prepare_commit(CA::Transaction*) + 276 8 QuartzCore 0x0000000188950e4c CA::Context::commit_transaction(CA::Transaction*, double, double*) + 676 9 QuartzCore 0x00000001887ae8f0 CA::Transaction::commit() + 644 10 AppKit 0x0000000183fdcb18 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 268 11 AppKit 0x0000000184992f04 ___NSRunLoopObserverCreateWithHandler_block_invoke + 60 12 CoreFoundation 0x00000001806d6d80 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 32 13 CoreFoundation 0x00000001806d6c6c __CFRunLoopDoObservers + 528 14 CoreFoundation 0x00000001806d629c CFRunLoopRun + 772 15 CoreFoundation 0x00000001806d593c CFRunLoopRunSpecific + 604 16 HIToolbox 0x000000018ac9e448 RunCurrentEventLoopInMode + 288 17 HIToolbox 0x000000018ac9e0d8 ReceiveNextEventCommon + 216 18 HIToolbox 0x000000018ac9dfdc _BlockUntilNextEventMatchingListInModeWithFilter + 72 19 AppKit 0x0000000183eb4ed0 DPSNextEvent + 656 20 AppKit 0x000000018469feec -[NSApplication(NSEventRouting) nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 712 21 AppKit 0x0000000183ea837c -[NSApplication run] + 472 22 acord 0x0000000100c45290 P110TARGETAPP$$TTARGETAPPLICATION$$$_EVENTLOOP (p110TargetApp.pas:5781) 23 acord 0x0000000100bc82e8 PASCALMAIN (Accord.pas:154) 24 acord 0x000000010159ab40 FPC_SysEntry + 28 25 acord 0x000000010156f770 FPC_SYSTEMMAIN + 76 26 acord 0x0000000100bc814c main + 8 27 ??? 0x00000001802790e0 0x0 + 0 {....} Thread 14: 0 ??? 0x0000000000000000 0x0 + 0 Thread 9 crashed with arm64 Thread State: x21: 0x000000016f7bb270 x2: 0x0000000169a00658 x16: 0x00000001887fef60 x3: 0x000000016f7b6a20 x22: 0x000000016f7b6a20 x4: 0x0000000000000000 x17: 0x00000001887feeb0 cpsr: 0x0000000060001000 x5: 0x0000000000000000 x23: 0x0000000000000000 x6: 0x0000000000000001 x18: 0x0000000000000000 x10: 0x0000000188af7000 lr: 0x0000000188922d90 x7: 0x0000000000000000 x24: 0x0000000169a00658 x11: 0x0000000000000000 x8: 0x0000000000000007 x19: 0x000000016f7b6a70 x25: 0x0000000188b0d968 x9: 0x0000000000000001 x12: 0x0000000000000008 fp: 0x000000016f7b6960 x26: 0x000000016f7ca270 x13: 0x0000000000000009 pc: 0x0000000188923428 x27: 0x0000000000000001 x14: 0x0000000000000001 x20: 0x000000016f7b8a70 x0: 0x000000016f7ca270 sp: 0x000000016f7b6940 x28: 0x0000000000000000 x15: 0x0000000000000012 x1: 0x0000000144808e00 In Xcode we might see a divide by zero like: 0x189247428 <+268>: fdiv EXC_BAD_INSTRUCTION (code=1, subcode=0x2e23fc03) Any help with interpreting/debugging this type of crash would be appreciated.
2
0
498
Feb ’24
TableView.makeView question
Is it possible that I bypass tableView.makeView so that I can create a NSTableCellView on the fly (based on some logics)? func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -&gt; NSView? { if NSTableColumn.identifier.rawValue == "labelColumn" { let myCellView = NSTableCellView() myCellView.textField.strinValue = "label text" return myCellView } else { let complexView = loadFromNib() // of NSTableCellView // populate complexView return complexView } }
0
0
350
Jan ’24
is it possible to operate `NEDNSProxyProvider` transparent mode
My macOS application utilizing NEDNSProxyProvider. i have a requirement to intercept only DNS requests of a certain query type, while others are expected to continue to their respective origin. For TCP there are two kinds of extensions NEAppProxyProvider and NETransparentProxyProvider. The latter is capable of returning NO from handleNewFlow causing the flow to proceed to communicate directly with the flow’s ultimate destination, instead of closing the flow. Is there a way to configure NEDNSProxyProvider to work in transparent mode for letting the flow to proceed to communicate directly? Current NEDNSProxyProvider limitation of dropping the connection when NO is returned requies me to open new socket and proxy the requests which causes noticable performance degradation under load.
2
0
502
Jan ’24
Xcode 15.2 - ObjC Swift Bridging broken?
I have an older project with a mixed ObjC + Swift codebase. I'm in the process of converting everything to Swift in the hopes that Xcode will work better again when the Codebase is not mixed anymore. This is an example of the issues I'm currently facing: The class IVMapViewController is defined in ObjC and the property mapViewModel is declared in the ObjC Header fine. The ObjC Header file is included in the bridging header. I'm trying to access the property mapViewModel in an swift extension on the same class. I can actually compile & run the code just fine, but Xcode Autocompletion does not work, and Xcode generates "Phantom" errors in the Issue Navigator (those errors also stay there when a build completes successful) On the other hand, if I put an actual error in the code, compilation fails, but the actual error will NOT show up in the Issue Navigator. I'll have to dig through the build log to find the actual error. Am I doing anything wrong? Do I need to adjust some project setting?
0
0
474
Jan ’24
Xcode cannot recognize generic methods
In objective-c, I created a category, like @interface NSArray <__covariant ObjectType> (ppEx) @end Look at this ObjectType, I wrote a method like - (NSArray *)pp_map:(id(^)(ObjectType element))block;which act like the map function in Swift. you can call it like NSArray <NSString *>*values = @[@"1", @"2", @"3", @"4"]; NSArray *valueMap = [values pp_map:^id _Nonnull(NSString * _Nonnull element) { return [NSString stringWithFormat:@"Hello %@", element]; }]; Now I need to add a property like mapBlock, I want to realize the same func; @property (nonatomic, copy) NSArray *(^mapBlock)(id(^paramBlock)(ObjectType element)); I did it. But when I call this method in Xcode, it can't complete automatically. values.mapBlock(^id _Nonnull(ObjectType _Nonnull element) { }) It's unable to recognize type NSString, and always show ObjectType which can cause error. I can manually change it to NSString, but it's too complicated. I think it's a problem of Xcode. Can anybody help me?
1
0
479
Jan ’24
Capabilities of Sensitive Content Analysis and iOS 17?
Hello. I have three questions about the Sensitive Content Analysis (SCA) framework: SCA seems to be asynchronous. Is there a limit to how much a single app can send through it at a time? For video analysis, can the video be broken into smaller chunks, and then all chunks be hit concurrently? Can a video stream be sampled as it's being streamed? e.g. Maybe it samples one frame every 3 seconds and scans those? Thanks.
0
0
517
Jan ’24
Hashable class extending NSObject?
I have some Swift classes in my project that extend an Objective-C base class, which in turn extends NSObject. I did this years ago when Swift was new in order to take advantage of some Objective-C code that was difficult to rewrite in Swift. It's not a common situation but it has been working fine for a long time. One of these classes is used as the key to a Dictionary and thus needs to be Hashable. The way I did this was to implement an == function and override the 'hash' property. It is a very simple case where the identity of the object is based on a single integer: static func == (lhs: FishModel, rhs: FishModel) -> Bool { return lhs.fishId == rhs.fishId } override var hash: Int { return fishId } I believe that I initially tried to add "Hashable" to the class definition but was told it was redundant. I'm not sure why that is, but it worked fine without it. Today I took the latest Xcode update to 15.2, and now my project won't compile anymore. The compiler error says that my class "does not conform to protocol Hashable". Adding Hashable to the class definition did not fix it. There are also some unusual errors about missing files, such as abi.json, swiftdoc, swiftmodule, and swiftsourceinfo. Was this caused by the Xcode update? How do I fix it?
2
0
772
Jan ’24
Clearing notifications not working for OS 17
My application requires me to clear all the notifications from the notification centre after a certain time duration. I have tried using a combination of removeAllDeliveredNotifications & removeAllPendingNotificationRequests and they work fine up until OS 17. So then I tried using removeDeliveredNotificationsWithIdentifiers & removePendingNotificationRequestsWithIdentifiers to check if it works consistently for all OS, but they hasn't worked either. Is there any other way to clear the notifications consistently for all OS?
1
0
520
Jan ’24
FileManager.enumerator and URL problem
I have the following pseudo code: func load(at packageURL: URL) { let realPackageURL = packageURL.resolvingSymlinksInPath() guard let it = fileMan.enumerator(at: realPackageURL) for case let fileURL as URL in it { print(fileURL) // Get filename relative to package root directory let relativeFileName = String(filePath.suffix(filePath.count - packagePath.count)) } } When called with "file:///tmp/some.app", the enumerated fileURL is actually file:///private/tmp/GIMP.app/Contents/ packageURL.resolvingSymlinksInPath() actually does nothing, I assume /tmp is a hard link. This makes it impossible to get a correct relative path. Is there any remedy for this?
2
0
488
Jan ’24
iOS17.2 change orientation
I have this Objective-C code that works well if placed inside viewDidAppear method - rotates view into the Portrait orientation; UIWindowScene *windowScene = self.view.window.windowScene; if (!windowScene) { return; } UIWindowSceneGeometryPreferences *preferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:UIInterfaceOrientationMaskPortrait]; [windowScene requestGeometryUpdateWithPreferences:preferences errorHandler:^(NSError * _Nonnull error) { // Handle error here }]; Now I need to do that same rotation after user pressed Read button but before the selected document is loaded in another view. The problem - I can't figure out how to force view update after the code is executed. I see initial view rotated only after exiting that selected document, but I need it rotated before entering it. Thank you
3
0
739
Jan ’24
Xcode 15.1 and 15.2 Objective-C Category/Extension Creation Issue
I'm encountering an issue with the latest versions of Xcode (15.1 and 15.2) while programming in Objective-C. When I try to create a category or an extension for a class, the process does not succeed and there is no response, with the category file not being created. This problem was not present in Xcode 15.0.1. My development environment is macOS Ventura 13.6.1. This bug is affecting my development work significantly. Could you please investigate this issue and provide a solution? Thank you for your assistance. 我在使用最新版本的Xcode(15.1和15.2)进行Objective-C编程时遇到了一个问题。当我尝试为一个类创建分类或扩展时,过程并不成功,没有任何反应,且分类文件没有被创建。在之前的版本Xcode 15.0.1中并没有这个问题。我的开发环境是 macOS Ventura 13.6.1。这个bug严重影响了我的开发工作。您能否调查此问题并提供解决方案?感谢您的帮助。
4
0
1.2k
Jan ’24
Reading multi parts of a file concurrently
I have a need to read first half and second half of a file concurrently. Is there any best practices for this scenario? BTW, I did research on DispatchIO but it turned out DispatchIO is all about asynchronous operations on a single file handle; it cannot perform parallel reading. // naive approach Task { fileHandle.read(into:buffer) } Task { // seek to file size / 2 fileHandle.read(into:buffer) }
5
0
751
Jan ’24
Changing screen orientation without rotation and view resizing animations
I need to instantly and without rotation animation change the screen orientation (and accordingly the size of the frame self.view in the UIViewController). If I do it like this in UIViewController: - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id&lt;UIViewControllerTransitionCoordinator&gt;)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [CATransaction begin]; [CATransaction setDisableActions:YES]; [coordinator animateAlongsideTransition:^(id&lt;UIViewControllerTransitionCoordinatorContext&gt; context) { [self.view setFrame:CGRectMake(0, 0, size.width, size.height)]; } completion:^(id&lt;UIViewControllerTransitionCoordinatorContext&gt; context) { [CATransaction commit]; }]; } Then, at the moment the screen orientation changes to, I see a flickering of view. How can I do what is necessary?
0
0
510
Jan ’24