2010-04-01 6 views
1

Je suis en train de mettre un texte sur une étiquetteComment vérifier si la variable est une chaîne CFString?

descriptionLabel.text = [NSString stringWithFormat:mySTUser.bio]; 

La propriété bio de mySTUser est un NSString. Parfois, ce n'est pas un NSString quand je le mets. Comment puis-je vérifier si mySTUser.bio est un NSString afin que je puisse l'empêcher d'être affecté à mon texte d'étiquette?

+1

Quoi d'autre pourrait-il être, sinon une chaîne? En outre, vous ne devez pas utiliser 'stringWithFormat:' sans une chaîne de format. Il devrait être '[NSString stringWithFormat: @"% @ ", mySTUser.bio]' ou '[NSString stringWithString: mySTUser.bio'. – Chuck

Répondre

4
if (![mySTUser.bio isKindOfClass:[NSString class]]) { 
    // its not an NSString 
} 
+0

Merci pour le conseil. Cela fonctionne parfaitement. –

Questions connexes