Objective-C

RSS for tag

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

Posts under Objective-C tag

304 Posts
Sort by:
Post not yet marked as solved
19 Replies
24k Views
Will Apple continue to support it, or will we wake up one day to find that Swift is the only viable language?It's a serious question. Careers depend on it. I don't accept the "No comment" approach that Apple usually takes. It's cruel.I'm willing to put the time into learning Swift if I have to. I'm not going to do it if I don't. I want to know.Frank
Posted
by flarosa.
Last updated
.
Post not yet marked as solved
1 Replies
187 Views
I hope the table column show the values after I pressed the button. The following is the IBAction Button. - (IBAction)buttonTapped:(id)sender { //Filling the arrays Test_name = [NSArray arrayWithObjects:@"test_item_a",@"b",@"c",@"Current",nil]; Min = [NSArray arrayWithObjects:@"0.5",@"0.7",@"0.8",@"100",nil]; Max = [NSArray arrayWithObjects:@"5",@"5",@"9",@"140",nil]; uint16 index = 0; NSInteger i = 0; //Show_Datagrid this function move the above values to another 3 arrays table_item, //table_min, table_max. And the following code is just to verify the value. [self Show_Datagrid:index]; [self showMeg:@"Button Tapped!2\n"]; [self showMeg:[table_item objectAtIndex:0]]; [self showMeg:@"\n"]; [self showMeg:[table_min objectAtIndex:0]]; [self showMeg:@"\n"]; [self showMeg:Column_test_item.identifier]; //call this function to show the values in tableview. [self tableView:_tableview objectValueForTableColumn:Column_test_item row:i]; } following is the function (Column_test_item.identifier is verified correct.): -(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { if ([aTableColumn.identifier isEqualToString:@"no"]) return [table_no objectAtIndex:rowIndex]; if ([aTableColumn.identifier isEqualToString:@"item"]) return [table_item objectAtIndex:rowIndex]; if ([aTableColumn.identifier isEqualToString:@"min"]) return [table_min objectAtIndex:rowIndex]; if ([aTableColumn.identifier isEqualToString:@"max"]) return [table_max objectAtIndex:rowIndex]; if ([aTableColumn.identifier isEqualToString:@"value"]) return [table_value objectAtIndex:rowIndex]; if ([aTableColumn.identifier isEqualToString:@"status"]) return [table_status objectAtIndex:rowIndex]; return [table_no objectAtIndex:rowIndex]; } I thnik I called that function in wrong way. Shouldn't I input NSTableColumn parameter Column_test_item directly? Column_test_item is an IBOutlet I connected to the specfic test item column. And how does this function know which column it want to fill up the value, based on the second parameter I input?
Posted
by kp008114.
Last updated
.
Post not yet marked as solved
1 Replies
430 Views
Hi all, I'm currently implementing a feature that performs customized behavior in each desktop (space). As far as I know, Apple does not have an API that can enumerate all spaces under each screen. I've only found a way that can get all spaces, but cannot find any method on how to determine each space belongs to which screen. Can somebody help me out? Thanks in advance.
Posted Last updated
.
Post not yet marked as solved
2 Replies
2.7k Views
UIImageWriteToSavedPhotosAlbum work well in iOS 9/10but crashed in iOS 11what 's problem?NSData* imgdata = [NSData dataWithContentsOfFile:path]; if (nil != imgdata) { UIImage* saveImg = [[UIImage alloc] initWithData:imgdata]; if (nil != saveImg) { UIImageWriteToSavedPhotosAlbum(saveImg, nil, nil, nil); return 1; } }
Posted
by leke360.
Last updated
.
Post not yet marked as solved
0 Replies
162 Views
Hi Team, I facing a problem with building my app, After update into the latest version Xcode 13.4, I had a few problems which were successfully solved. However one of them stopped me for a few hours. The problem is with Swift Compiler or Bridging Headers is unsupported, I really don't know what causes problems. On several forums I often read that is important to set: Build Settings > Build Options > Build Libraries for Distribution = YES If I set it  ‘YES’ I getting - error: using bridging headers with module interfaces is unsupported If I set it  ‘NO’ I getting - error: module compiled with Swift 5.0.1 cannot be imported by the Swift 5.2.2 compiler, for some framework or classes. Can you please guide me, what should I do to resolve this issue ?
Posted Last updated
.
Post not yet marked as solved
1 Replies
184 Views
I am trying to develop a plug in for motion in Objective-c using the FxPlug template and so far I have been having issues with getting "NSOpenPanel" to be called from a push button in order to get a file dialog window, similar to the "File" generator present in Motion. [paramAPI addPushButtonWithName: @"MIDI file" parameterID: 1 selector: @selector(MIDI_func) parameterFlags: kFxParameterFlag_DEFAULT] I have tried to call NSOpenPanel through "dispatch_async" so that it would run on the main thread and thus not crash but when I press the button it appears not to work - (void)MIDI_func {     NSLog(@"Button pressed");     dispatch_async(dispatch_get_main_queue(), ^{         NSOpenPanel* openDlg = [NSOpenPanel openPanel];         [openDlg setCanChooseFiles:YES];         [openDlg setAllowsMultipleSelection:NO];         [openDlg setCanChooseDirectories:NO];         if ([openDlg runModal] == NSModalResponseOK) {             NSArray* urls = [openDlg URLs];             for(NSInteger i = 0; i < [urls count]; i++ ) {                 NSString* url = [urls objectAtIndex:i];                 NSLog(@"Url: %@", url);             }         }     }); } How can I achieve this or is there a function in the FxPlug SDK that will let me open a file dialog from the host application?
Posted Last updated
.
Post not yet marked as solved
1 Replies
119 Views
I am attempting to dynamically clone a class object in Swift using reflection and the setValue function. This class contains an enum property that is backed with an Int, which is causing this dynamic reflection to crash: @objc enum Status : Int { case green case yellow case red } @objc class State : NSObject { @objc var status : Status init(_ status: Status) { self.status = status } } func testReflectiveClone() { let state1 = State(.green) let state2 = State(.yellow) let state1Mirror = Mirror(reflecting: state1) for property in state1Mirror.children.enumerated() { let label = property.element.label state2.setValue(property.element.value, forKey: label!) //crashes here } } This test function is throwing the following error in XCode: -[__SwiftValue longLongValue]: unrecognized selector sent to instance 0x600001e5a340 (NSInvalidArgumentException) Is it even possible to dynamically set enum values? What modification would I need to make to get this to work?
Posted
by mackers.
Last updated
.
Post not yet marked as solved
0 Replies
123 Views
I am using EventKit to fetch all events from the default Apple Calendar in my app. When there is a custom recurring event in the Apple Calendar with multiple days of recurrence then EventKit returns an array of daysOfTheWeek in the recurrence rule What I mean is Event_A is recurring weekly every Friday and Saturday then EventKit returns an array of objects like this   calendar = "testingcurvecalendar@gmail.com";   endDate = "2022-07-30 11:00:00";   id = "5FFF5521-18BB-497C-8EF5-4E72647A6A24:2AE552B8-85C4-489C-8A36-DACF95D83E61";   lastModifiedDate = "2022-05-20 10:25:01";   rrule =   {     calendar = gregorian;     daysOfTheWeek =     (             {         dayOfTheWeek = Friday;         weekNumber = 0;       },             {         dayOfTheWeek = Saturday;         weekNumber = 0;       }     );     freq = weekly;     interval = 1;     until =     {       count = 0;       date = "2022-07-31 23:59:59";     };   };   startDate = "2022-07-30 10:00:00";   title = MultipledayswithEnd; }, But if an event is recurring for only single day then eventkit does not return daysOfTheWeek object i.e. Event_B is recurring weekly every Monday then the object received from the eventkit is as follows   calendar = "testingcurvecalendar@gmail.com";   endDate = "2022-07-27 11:00:00";   id = "5FFF5521-18BB-497C-8EF5-4E72647A6A24:C57AFD95-75A0-4F75-B4F0-00D7321BFB21";   lastModifiedDate = "2022-05-20 10:27:23";   rrule =   {     calendar = gregorian;     freq = weekly;     interval = 1;     until =     {       count = 0;       date = "2022-07-31 23:59:59";     };   };   startDate = "2022-07-27 10:00:00";   title = Singlewithend; }, The issue is I would like to display the day of recurrence in my app which I am able to in case of Multi-day recurring events because I receive the days in dayOfTheWeek object but I cannot do it in Single-day recurring events. The code for fetching events from the Calendar is as follows   NSPredicate *fetchCalendarEvents = [eventStore predicateForEventsWithStartDate:[NSDate date] endDate:endDate   calendars:calendarArray];   NSArray *matchingEvents = [eventStore eventsMatchingPredicate:fetchCalendarEvents];   NSMutableArray * eventsDataArray = [self eventsToDataArray:matchingEvents]; Can someone please help me with this issue?
Posted Last updated
.
Post not yet marked as solved
1 Replies
304 Views
The didFinishWithResult delegate method of MFMessageComposeViewController shows that the message has been sent successfully, even when the device is in airplane mode or when the device has no SIM,but the message sending is failed.The delegate does not go through the failure state.Why doesnt it go to failure state?.Please give me some suggestion on this. The code is given as below: { &#9;&#9;MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; &#9;&#9;picker.messageComposeDelegate = self; &#9;&#9; &#9;&#9;// You can specify one or more preconfigured recipients.&#9;The user has &#9;&#9;// the option to remove or add recipients from the message composer view &#9;&#9;// controller. &#9;&#9;/* picker.recipients = @[@"Phone number here"]; */ &#9;&#9; &#9;&#9;// You can specify the initial message text that will appear in the message &#9;&#9;// composer view controller. &#9;&#9;picker.body = @"Hello from California!"; &#9;&#9; &#9;&#9;[self presentViewController:picker animated:YES completion:NULL]; } // //&#9;messageComposeViewController:didFinishWithResult: //&#9;Dismisses the message composition interface when users tap Cancel or Send. //&#9;Proceeds to update the feedback message field with the result of the //&#9;operation. // (void)messageComposeViewController:(MFMessageComposeViewController *)controller &#9;&#9;&#9;&#9;&#9;&#9;&#9;didFinishWithResult:(MessageComposeResult)result { &#9;&#9;self.feedbackMsg.hidden = NO; &#9;&#9;// Notifies users about errors associated with the interface &#9;&#9;switch (result) &#9;&#9;{ &#9;&#9;&#9;&#9;case MessageComposeResultCancelled: &#9;&#9;&#9;&#9;&#9;&#9;self.feedbackMsg.text = @"Result: SMS sending canceled"; &#9;&#9;&#9;&#9;&#9;&#9;break; &#9;&#9;&#9;&#9;case MessageComposeResultSent: &#9;&#9;&#9;&#9;&#9;&#9;self.feedbackMsg.text = @"Result: SMS sent"; &#9;&#9;&#9;&#9;&#9;&#9;break; &#9;&#9;&#9;&#9;case MessageComposeResultFailed: &#9;&#9;&#9;&#9;&#9;&#9;self.feedbackMsg.text = @"Result: SMS sending failed"; &#9;&#9;&#9;&#9;&#9;&#9;break; &#9;&#9;&#9;&#9;default: &#9;&#9;&#9;&#9;&#9;&#9;self.feedbackMsg.text = @"Result: SMS not sent"; &#9;&#9;&#9;&#9;&#9;&#9;break; &#9;&#9;} &#9;&#9; &#9;&#9;[self dismissViewControllerAnimated:YES completion:NULL]; } For me and other multiple devices when we press "CANCEL" or "SEND" message the correct delegates are fired. But when I switch ON the AIRPLANE Mode or the device with no SIM still the MessageComposeResultSent Is fired. Can some one tell clearly when the MessageComposeResultFailed is fired? Any live steps? Please kindly help me This is my last hope. I just want know when the Status Failed gets fired with step by step procedure
Posted
by AlexBingo.
Last updated
.
Post marked as solved
3 Replies
825 Views
I am seeing a weird thing when compiling a large iOS project which is predominantly in Objective C. I have two machines, a Mac Studio Ultra and a MacBook Pro with an M1 Pro. It appears the time taken to compile on the MBP (M1 Pro) currently 30-50% faster at building the same project when compared to the Mac Studio!!!! Not possible I hear you say... I have done everything to ensure both systems are identical down to installing the same copy of the same account and settings on both machines. When I look into the build times in Xcode I can see the time taken to compile the Objective C files. On the Studio a typical file is taking between 5 seconds and 7 seconds per file!!, whereas on the MBP (Pro) the same files are taking 0.7 and 1.2 seconds. Strangely, when compiling the Swift files in a pure swift project the Studio will beat the MBP (Pro) by around 20% - 30%. This sounds like a issue with the Studio itself. Is anyone else seeing the same issue?
Posted Last updated
.
Post not yet marked as solved
2 Replies
298 Views
Code that works w/ any iOS and Xcode 12, and also works w/ Xcode 13.3.1 and iOS15.4 and earlier....does not work with Xcode 13.3.1 and iOS15.           NSPredicate *myButtonPredicate = [NSPredicate predicateWithFormat:@"self.accessibilityLabel = %@",@"My Button"];             if ([arrayOfButtons filteredArrayUsingPredicate:myButtonPredicate].count == 0 I get a SIGABRT w/o any other debug info on the 2nd line of that code sample. Did something change w/ NSPredicate/NSArray/NSPredicateSupport?
Posted
by tsaarva.
Last updated
.
Post marked as solved
4 Replies
11k Views
I had many swift compiler errors of this type : "Cannot find type 'className' in scope" after passing from Xcode 12.5 to Xcode 13. And the error is always referred to Objective-C classes. The project is for an iOS 11 app for iPad. The bridging-header is correctly set and the project with the same build-settings has never given this error before Xcode 13. I'll try to clean the derived data folder without success. the strange thing is project compile successfully and I can run on simulator as well but after few second from a successful compilation on any swift files that use objective-c class is fired the swift compiler error. Any idea? thanks
Posted
by mrcdev.
Last updated
.
Post not yet marked as solved
0 Replies
124 Views
I have an AVFoundation-based live camera view. There is a button by which I am calling AVCaptureDevice.showSystemUserInterface(.videoEffects) so that the user can activate the Portrait Effect. I have also opted in by setting "Camera — Opt in for Portrait Effect" to true in info.plist. However, upon tapping on the button I see this screen (The red crossed-off part is the app name): I am expecting to see something like this: Do you have any idea why that might be?
Posted
by Asteroid.
Last updated
.
Post not yet marked as solved
3 Replies
4.9k Views
After spending a few hours to integrate swift files successfully to my Objective-C based iOS project, I face the next challenge now :In one of my Objective-C class header (Say, MyObjCClass.h), I do the forward declaration for MySwiftClass.In the respective .m file, I define an instance of MySwiftClass _swiftClassInstance.In the init method of MyObjCClass, I try to instantiate it as follows : _swiftClassInstance = [[MySwiftClass alloc] init]; When I compile the code, I get 2 errors :Receiver 'SocketIOClient' for class message is a forward declarationReceiver type 'SocketIOClient' for instance message is a forward declarationI have already done following :Imported MyProject-Swift.h in the MyObjCClass.m file.Marked the swift class with @objc and openSo, what can be the reason for the issue?
Posted
by HarishJ.
Last updated
.
Post not yet marked as solved
4 Replies
1.6k Views
Hi, I am writing a Swift framework that primarily serves as a wrapper for a linear algebra library written in C. The framework therefore is a mixture of Swift and Objective C (the Objective C part is there to serve as a bridge to allow the Swift code to talk to the C I have reviewed the documents on Clang modules and looked at various code examples on the Web. However, I am still not finding a clear path and have had difficulties getting the code to compile (I am also unclear what the official recommendations are for achieving the goal I desire). Here are a few questions: 1) Is it good practice to create mixed languages frameworks that are a combination of Swift and Objective C++? If so, are there examples available that show best practices? If not, what is a workaround? 2) I don’t want to expose the Objective C++ part of the code to the consumer of my framework. I am not clear how to do this. I have read about private modules. However, I am unclear about how to properly use private modules in this context and again lack clear examples. 3) What is the recommended practice when creating module.map files in XCode when XCode itself generates a default module.map file when building a framework? Again, there are some examples on the Web, but I am unclear whether they are correct an none of them explicitly suits my goals. 4) Where is the official documentation on how to properly use module.map files in XCode especially with respect to building frameworks that rely on both Swift and Objective C++? 5) Although I know that if this weren’t a framework, I could create a bridging header to allow Swift to talk to Objective C++. However, in the case of a module there is an umbrella header. My understanding of the umbrella header is that it pertains to code that will consume the framework, not for other code in the framework itself. Can you somehow combine an umbrella header and a bridging header in a framework? Thanks in advance
Posted
by jon2718.
Last updated
.
Post not yet marked as solved
2 Replies
177 Views
I'm adding a WKWebView to my (Mac) app, and it works fine except that the navigationDelegate is never called. Even stranger, if that delegate implements decidePolicyForNavigationAction, that method is never called either, but as a side effect the view now won't load any pages! In detail: I've created a class implementing WKNavigationDelegate, I've implemented some of the methods, and assigned an instance to the view's navigationDelegate property. Easy stuff. I've done this in the past using the old-school WebView class. I've triple-checked my work. As an experiment, I added a -respondsToSelector: method to my delegate class and made it log the selector. I see it being called several dozen times, with the selectors for all of the delegate methods and many other private(?) methods; so I know WebKit sees my object. It just never calls it at all. My hunch so far is that this is an OS bug, that Apple no longer bothers to test WebKit APIs in Objective-C. I'd hate for that to be true. (I realize Obj-C is basically deprecated nowadays. I'm using it because my non-UI code is all in C++, and it's vastly easier to integrate with C++ in Obj-C. To use Swift I'm going to have to wrap my API in C functions, yuck.)
Posted
by snej.
Last updated
.