How can I convert from std::string to NSString in this case?
void Piles::imagePlacer(Card card, int xCoord, int yCoord) {
string cardType = card.toString();
UIImageView *cardImg = [[UIImageView alloc]
initWithImage:cardType];
cardImg.frame = CGRectMake(xCoord, yCoord, 126, 190);
[self.view addSubview:cardImg];
}
I want to use a string as the name of the image (assuming I have a list of UIImages somewhere with names that correspond to all possible strings stored in cardType)?
Just go through a C string:
[NSString stringWithUTF8String:cardType.c_str()]
or using the new syntax:
@(cardType.c_str())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With