Hi!
I have a xcode workspace with first objectiveC framework (let’s call it framework#1). This framework has some singletons (+(instancetype)shared using the dispatch_once idiom.
This code is pretty straight forward and used everywhere :
+ (instancetype)shared {
static dispatch_once_t onceToken;
static OGAKeyManager *instance = nil;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
I have a second framework (framework#2) in Swift that uses theses singletons (the framework#1 is added as do not embeed in the framework settings).
And I have an application that uses both frameworks.
If I make a breakpoint inside the dispatch_once alloc/init, I see that I enter 2 times : once when the shared method is called from framework#1 and another one when it’s called from framework#2.
How is that even possible ? Isn't dispatch_once supposed to handle this ?
I asked chatGPT, it points out to some objC/Swift interoperability, but honestly, I don't see what I can do to make it work correctly.
There is no circular dependency (framwork#2 uses framwork#1, but framwork#1 has no clue of framwork#2 existence)
Maybe it has something to do with sandbox, but I don't see how can it be.
Does anyone experienced some weird behavior like this ?
Thanks
Objective-C
RSS for tagObjective-C is a programming language for writing iOS, iPad OS, and macOS apps.
Posts under Objective-C tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi,
I am trying to extend the pytorch library. I would like to add MPS native Cholesky Decomposition. I finally got it working (mostly).
But I am struggling to implement the status codes.
What I did:
// init status
id<MTLBuffer> status = [device newBufferWithLength:sizeof(int) options:MTLResourceStorageModeShared];
if (status) {
int* statusPtr = (int*)[status contents];
*statusPtr = 42; // Set the initial content to 42
NSLog(@"Status Value: %d", *statusPtr);
}
else {
NSLog(@"Failed to allocate status buffer");
}
...
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer) {
// Your completion code here
int* statusPtr = (int*)[status contents];
int statusVal = *statusPtr;
NSLog(@"Status Value: %d", statusVal);
// Update the 'info' tensor here based on statusVal
// ...
}];
for (const auto i : c10::irange(batchSize)) {
...
[filter encodeToCommandBuffer:commandBuffer
sourceMatrix:sourceMatrix
resultMatrix:solutionMatrix
status:status];
}
(full code here: https://github.com/pytorch/pytorch/blob/ab6a550f35be0fdbb58b06ff8bfda1ab0cc236d0/aten/src/ATen/native/mps/operations/LinearAlgebra.mm)
But this code prints the following when input with a non positive definite tensor:
2023-09-02 19:06:24.167 python[11777:2982717] Status Value: 42
2023-09-02 19:06:24.182 python[11777:2982778] Status Value: 0
initial tensor: tensor([[-0.0516, 0.7090, 0.9474],
[ 0.8520, 0.3647, -1.5575],
[ 0.5346, -0.3149, 1.9950]], device='mps:0')
L: tensor([[-0.0516, 0.0000, 0.0000],
[ 0.8520, -0.3612, 0.0000],
[ 0.5346, -0.3149, 1.2689]], device='mps:0')
What am I doing wrong? Why do I get a 0 (success) status even tough the matrix is not positive definite.
Thank you in advance!
I have a history objective-c project, and now i want to use Live Acitivity feature in that objc project.
first i implement a live activity in swift project, and it works well on iphone devices.
then i copy same codes from swift project to objective-c project, build and run on same iphone device, no error or warning generates, but Live Activity UI can't seen.
can someone tell me how to fix it ? and only swift project can support Live Activity ?
My apps were working fine and suddenly started crashing on older devices. I have iPhone 7 Plus to test and after updating it to 15.7.8, the installed apps which were working before started crashing. The specific code where they are crashing is
if([testStats objectForKey:TEST_STATS_ARRAY]) {
statArray = [testStats objectForKey:TEST_STATS_ARRAY];
}
else {
statArray = [[NSMutableArray alloc] init];
[testStats setValue:statArray forKey:TEST_STATS_ARRAY];
}
Hello everyone! Here with another graphics api question but slightly different. I'm currently looking at 2 SDK's for physics called PhysX and Bullet. The game asphalt 9 uses metal and bullet and I would like to do the same with asphalt 9. With metal 3 out and stable it seems, I would like to use one of these engines for my upcoming metal api rendering engine. Bur there's a catch, I wish to use objective-c or c++ for both the rendering engine and the physics engine as I mentioned above, but not me touching swift(its a good language but i wish to use c++ for game development). What do you guys say about this?
Hey all. I took a look at a video that caught my attention(https://developer.apple.com/videos/play/wwdc2021/10081) and wish to use this for my ios and iPad game. However, the language used here is swift, and want to use either objective-c or c++. Did anyone here used this method shown is this video but without swift?
I have an application which will launches another application as a child process.
The child application does not need the dock icon, we use [NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory]; to achieve it.
However, I have discovered that the dock icon cannot be perfectly hidden.
The number of recently used apps that aren’t already in dock(not choose keep in dock) less than three: The icon of the child application remains in the dock without being hidden.
The number of recently used apps that aren’t already in dock(not choose keep in dock) more than three: The icon of the child application appears a few milliseconds.
Even though add LSUIElement key in the Info.plist can work, we are seeking a programmatic modification.
I was migrating from Xcode 14 -> 15, and noticed that my code was failing with dyld[46534]: Symbol not found: _OBJC_CLASS_$_NSError
I was able to debug the problem to some old objective c code, as documented in this thread: https://github.com/RonRadtke/react-native-blob-util/issues/273
The error seems to stem from this particular try catch block
@try {
// Some code
}
@catch(NSError *er) {
// handle error
}
When I convert the code to catch an NSException instead, the runtime error goes away. Understandably, according to the apple docs, it should be throwing an NSException in the first place, but the documents do say
Important: Although you can throw and catch objects other than NSException objects, the Cocoa frameworks themselves might only catch NSException objects for some conditions. So if you throw other types of objects, the Cocoa handlers for that exception might not run, with undefined results. (Conversely, non-NSException objects that you throw could be caught by some Cocoa handlers.) For these reasons, it is recommended that you throw NSException objects only, while being prepared to catch exception objects of all types.
So it seems like this should not have produced a runtime error. I wanted to flag this in case the underlying code behind the @try @catch changed unintentionally.
I have an Objective C++ wrapper class called ImageDividerWrapper in which there is a function I want to use in a Swift class called FrameProcessor.
Inside the ImageDividerWrapper.h file I made sure to import the bridging header. I also double-checked that the bridging header was referenced and spelled correctly in Project/Build Settings/Swift Compiler. I also deleted derived data, cleaned build folder, etc..
Also imported ImageDividerWrapper.h into my bridging header file:
#import "ImageDividerWrapper.h"
And in my ImageDividerWrapper header file I include:
#import "Vsn3-Bridging-Header.h"
Unfortunately, I still continue to get the error: "No such module 'ImageDividerWrapper'" when trying to directly import the Objective C++ class into my Swift file with:
import ImageDividerWrapper
If anyone who has solved this problem before can point me in the right direction, I would appreciate it so much!
Thank you!
When I build and run my Objective-C project—consisting of the files main.m, BNRLogger.h, and BNRLogger.m—in Xcode, the function appLaunch: is supposed to be executed whenever a non-background application without the LSUIElement key in its Info.plist file launches on my MacBook. But that doesn't appear to be happening; the message "An app has started up!" doesn't show up in the Xcode console when an app (e.g., Blender) launches. What's going on? Have I failed to ensure that appLaunch: is called when an NSWorkspaceDidLaunchApplicationNotification is posted, or is no such notification being posted when an app launches?
This is what main.m looks like:
#import <Cocoa/Cocoa.h>
#import "BNRLogger.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
BNRLogger *logger = [[BNRLogger alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:logger
selector:@selector(appLaunch:)
name:NSWorkspaceDidLaunchApplicationNotification
object:nil];
[[NSRunLoop currentRunLoop] run];
}
return 0;
}
BNRLogger.h looks like this:
#import <Foundation/Foundation.h>
#ifndef BNRLogger_h
#define BNRLogger_h
@interface BNRLogger : NSObject
@end
#endif
And here are the contents of BNRLogger.m:
#import "BNRLogger.h"
@interface BNRLogger ()
- (void)appLaunch:(NSNotification *)note;
@end
@implementation BNRLogger
- (void)appLaunch:(NSNotification *)note {
NSLog(@"An app has started up!");
}
@end
How to Setup "Multi-OS Engine" in Xcode
Is there a way to catch the crashes from both swift and obj-c without using any 3rd party libraries?
I want a way to note that my app has crashed, no stack trace needed just want some count of crashes stored to user defaults.
I saw NSSetUncaughtExceptionHandler being used but it is only catching obj-c related errors.
eg. force unwrapping nil is not caught here.
I want a universal way of catching the crashes. also want to know if this can affect the crash reporting by 3rd party libraries
I have an app using in app purchase to buy diamonds And to buy diamonds i want to use in app purchase, Paid Apps agreement activated. I already defined product_id from API
[self.delegate applePayShowHUD];
NSDictionary *dics = @{
@"uid":[Config getOwnID],
@"coin":[dic valueForKey:@"coin_ios"],
@"money":[dic valueForKey:@"money"],
@"changeid":dic[@"id"]
};
[YBToolClass postNetworkWithUrl:@"Charge.getIosOrder" andParameter:dics success:^(int code, id _Nonnull info, NSString * _Nonnull msg) {
if (code == 0) {
NSString *infos = [[info firstObject] valueForKey:@"orderid"];
self.OrderNo = infos;//订单
//苹果支付ID
NSString *setStr = [NSString stringWithFormat:@"%@_testing",[dic valueForKey:@"product_id"]];
NSSet *set = [[NSSet alloc] initWithObjects:setStr, nil];
self.request = [[SKProductsRequest alloc] initWithProductIdentifiers:set];
self.request.delegate = self;
[self.request start];
}
else{
[self.delegate applePayHUD];
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD showError:msg];
});
}
} fail:^{
}];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
[self.delegate applePayHUD];
self.products = response.products;
self.request = nil;
for (SKProduct *product in response.products) {
NSLog(@"已获取到产品信息 %@,%@,%@",product.localizedTitle,product.localizedDescription,product.price);
self.product = product;
}
if (!self.product) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showAlertView:YZMsg(@"无法获取商品信息")];
});
return;
}
//3.获取到产品信息,加入支付队列
SKPayment *payment = [SKPayment paymentWithProduct:self.product];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
and i already put the product in app store connect like this
i put configuration too in xcode
<SKProduct: 0x2833d8890>: Skipping product "coin_3000_testing" because no price was available
I always get skipping product, Am i missing something here ?
I test this in real device directly from xcode, not testflight
the xcode will freze for 3mins when hit a breakpoint. it report "Fetching variables on ***'s iPhone"
it happens when hit a new breakpoint, and the xcode will freeze for 3mins, then it will be ok. anysolution? its wasting my time.
the xcode continue print the log below:
(arm64) /Users/xx/Desktop/patch/Project/Pods/TestSDK/vendor/***.framework/***(FPEncryptMsg.pb-c.o) 0x00000c22: unable to locate module needed for external types: /Users/packagedevice/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/38MC9CUKFC6LS/Darwin-MI6WZSG1PNOM.pcm
error: '/Users/packagedevice/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/38MC9CUKFC6LS/Darwin-MI6WZSG1PNOM.pcm' does not exist
Debugging will be degraded due to missing types. Rebuilding the project will regenerate the needed module files.
Our project has many dependencies which are binary file. And these dependencies are build in the remote serve。Anyone has ideas about this
I'm currently writing a code to achieve the RSA encryption via C++, and I stumbled across this error message when I was running it.
The first part of my code is to generate random prime numbers based on the digit from the input for the encryption. For example, if you enter 6 then the code will generate two prime numbers, M and m, between 100000 to 999999. The "fin" variable equals (M-1)*(m-1), and based on "fin" I will create an int array the size of [fin+1] in the "Random e" section. However, if I enter a number greater than 3 ( which means "fin" will go beyond 6 digits) the crash will occur and the error message will show.
I can't seem to find the problem anywhere, and if my input is no greater than 3 then the code will work exactly as I wanted it to. Is there something I missed? Thank you very much.
Xcode [14.3.1]
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
long long int gcd(long long int x, long long int y)
{
for (long long int t; y!=0; x=t)
{
t=y;
y=x%y;
}
return x;
}
long long int mod(long long int x, long long int y, long long int n)
{
if (x%n==0)
{
return 0;
}
long long int result;
for (result=1; y>1; x=(x*x)%n)
{
if (y%2==1)
{
result = (result * x)%n;
y=(y-1)/2;
}
else if (y%2==0)
{
y=y/2;
}
}
x=(x*result)%n;
return x;
}
int main()
{
// Random Prime Numbers------------------------------//
cout << "Input digits" << endl;
int k;
cin >> k;
cout << "Input letter for encryption" << endl;
char f;
cin >> f;
long long int M=pow(10, k)-1;
long long int m=pow(10, k-1);
bool prime[M+1];
memset(prime, true, sizeof(prime));
for(long long int p=2; p*p<=M; p=p+1 )
{
if (prime[p] == true)
{
for (long long int i=p*p; i<=M; i=i+p)
prime[i]=false;
}
}
int prime2[M+1];
for (long long int t=0; t<=M; t=t+1)
{
prime2[t]=1;
}
for (long long int p=m, t=1; p<=M; p=p+1)
{
if(prime[p]==true)
{
prime2[t]=p;
t=t+1;
}
}
long long int h = count(prime, prime+M+1, true);
long long int l = count(prime, prime+m, true);
h=h-l;
srand(time(NULL));
M=rand()%h+1;
m=rand()%h+1;
if (M==m)
{
m=(M*1000)%h+1;
}
if (M>h)
{
cout << "a=" << M << " error!" << endl;
}
else if (m>h)
{
cout << "b=" << m << " error!" << endl;
}
else
{
M=prime2[M];
m=prime2[m];
}
// Generating RSA keys----------------------------//
long long int n = M*m;
long long int fin = (M-1)*(m-1);
// Generating random e for the public key {e, n}--------//
long long int number[fin+1];
for (long long int i=0; i<=fin; i=i+1)
{
number[i]=0;
}
for (long long int i=2, k=1; i<=fin; i=i+1)
{
if (gcd(i, fin)==1)
{
number[k]=i;
k=k+1;
}
}
long long int z = fin+1-count(number, number+fin+1, 0);
srand(time(NULL));
long long int r = rand()%z +1;
long long int e = number[r];
long long int e2 = e;
long long int d=0;
for (long long int x=1, y=0, k=1, t=1; e2%fin!=0; k=1, d=y)
{
t=y;
y=x-y*(e2/fin);
x=t;
k=fin;
fin=e2%fin;
e2=k;
}
cout << endl << "The public key is {" << e << " , " << n << "}" << endl;
cout << "The private key is {" << d << " , " << n << "}" << endl;
// e、d、n acquired
// Encryption begins----------------------------//
long long int f2 = (int)f;
f2 = mod(f2, e, n);
cout << "The cyphertext is " << f2 << endl;
f2 = mod(f2, d, n);
f = (char)f2;
cout << f << endl;
}
I ran across the following crash while using one of our apps.
The app crashes since the recent iOS 17 beta builds.
The code crashes when using valueForKey on an NSArray with objects that implement NSCopying.
like: [@[[Sample new]] valueForKey:@"copy"];
or: [[Sample new] valueForKey:@"copy"];
header:
@interface Sample : NSObject<NSCopying>
- (Sample *)copy;
- (Sample *)copyWithZone:(nullable NSZone *)zone;
@end
implementation:
@implementation Sample
- (Sample *)copy {
return [super copy];
}
- (Sample *)copyWithZone:(nullable NSZone *)zone {
return self;
}
@end
Any idea why this might be happening?
I have created a feedback too: FB12819891
I have a static library staticLib.a which is witten mostly in C++ with one additional obj-C class MyClass. There are two dynamic libs, dynamicLib_A. dylib and dynamicLib_B.dylib are linked with the static lib.
When starting the application which loads the dynamic libs at runtime it comes out the following warning:
objc[15078]: Class MyClass is implemented in both /path/to/libdynamicLib_A.dylib (0x104f03f90) and /path/to/libdynamicLib_B.dylib (0x10dbf3f48). One of the two will be used. Which one is undefined.
It can be found that the C++ names are mangled. For instance, both libdynamicLib_A.dylib and libdynamicLib_B contains string:
__ZN18MyClassBC2Ev
It looks like the obj-c class name is not mangled. Both libdynamicLib_A.dylib and libdynamicLib_B contains string:
00000000012b7f48 S OBJC_CLASS$_MyClass
Question: How to avoid this warning? Why it complains only about the obj-c class but not the C++ class? Is this issue related to name mangling?
I'm getting undefined symbol for my own Swift class used from ObjC when linking in x86_64. I pinpointed the issue to using CheckedContinuation inside the class, because if I remove the use of it, it links. What could be the issue?
As per apple documentation we are setting textContentType with "" in order to disable password auto fill view option on keyboards which is working fine in all iOS versions below 17 beta.
Seems like it broke & password auto fill view option appearing on keyboards for iOS 17 beta versions even on setting textContentType with "" & inputAccessoryView as nil
self.username.textContentType = @"";
self.password.textContentType = @"";
After updating to xcode 14.3 with RN 0.69.9, my project can't build anymore. It's throwing the error for all of my custom view managers.
The error i'm getting is: A function declaration without a prototype is deprecated in all versions of C when I'm using RCT_EXTERN_MODULE
Output of npx react-native info:
System:
OS: macOS 13.4.1
CPU: (8) arm64 Apple M1 Pro
Memory: 77.59 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.13.1/bin/yarn
npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
Watchman: 2023.07.10.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.12.1 - /Users/avarisco/.rvm/gems/ruby-2.7.4/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 14.3/14E222b - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 18.0.0 => 18.0.0
react-native: 0.69.9 => 0.69.9
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found