Java to Objective-C conversion

Asked

Viewed 142 times

1

I need to convert this small code in Java to Objective-C to run a function in Objective-C, but there is an error that I haven’t been able to find yet.

Java code:

final char CHR0 = 0;
String finalprotocolo = "" + CHR0 + "";

String ligartv = "/ARP/IR/enviar/LigaTV" + finalprotocolo;
byte[] arrayligartv = ligartv.getBytes();

Code Objective-C:

    unichar c = 0x00;// c = 0x00;
    NSString *nova = [NSString stringWithFormat:@"%c", c];
    //NSString *nova = [NSString stringWithCharacters:&c length:1];
    // Pega a menssagem<br>
    NSString *final = @"/ARP/enviar/LigaTV";
    NSString *mensagem = [final stringByAppendingString:nova];

I need to perform the same Java code function, just by transforming byte 0 into String and adding the Objective-C message variable.

  • What error is happening?

  • I use this code to perform determines function in Arduino and with Java code it works, but with Objective-C no. Would it have some peculiarity in the language in question or is it code error? @Paulorodrigues

1 answer

1

I need to perform the same Java code function, just by transforming byte 0 into String and adding the Objective-C message variable.

An example of turning a unichar into Nsstring would be like code below:

- (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view, typically from a nib.
     unichar unicharA = 0x0391;
     NSLog(@"converterUnichar = %@", [self converterUnichar:unicharA])
}
-(NSString*) converterUnichar:(unichar) c{
     NSString *stringRetorno = [NSString stringWithCharacters:&c length:1];
     return stringRetorno;
}

Would that be all? I hope I helped, hug

  • I’m doing it this way @revton unichar c = 0x00; NSString *nova = [NSString stringWithCharacters:&c length:1]; Can be?

  • I created a method with your solution but I do not work, I would use the way I posted. -(Nsstring*) converterUnicharUser75138:(unichar) c{ Nsstring *nova = [Nsstring stringWithCharacters:&c length:1]; Return new; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.