Tag: 下标

系统字体中没有字形时如何下标字母?

我已经能够成功地在我的应用程序中下标数字: static const unichar kSubscriptZero = 0x2080; int numberOfHydrogens = 2; NSString *header1 = [NSString stringWithFormat:@"H%CO", kSubscriptZero + numberOfHydrogens]; 问题是这样的:我试图用unicode字符中的其他字符做同样的事情,但它不工作,我得到的只是一个方框而不是我的字符,事实certificate,这意味着我的字形没有该字符的字体。 我回顾了以前在这里问过的一个问题,并尝试了其他字符,而不是数字: if (section == whicheverSectionIndexIsCorrect) { NSString *plainText = @"2H2 + O2 → 2H2O"; id subscriptOffset = @(-0.5); // random guess here, adjust offset as needed NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:plainText]; // apply attributes […]

铸造NSDictionary作为词典Swift

我已经看到这在其他问题解决 – 但我认为,因为这个NSDictionary是通过下标访问它抛出一些错误。 func pickRandomRecipe(arrayOfRecipes: NSArray) -> Dictionary<String,Any> { let randomRecipeIndex = Int(arc4random_uniform(UInt32(arrayOfRecipes.count))) //Could not cast value of type '__NSDictionaryI' (0x7fbfc4ce0208) to 'Swift.Dictionary<Swift.String, protocol<>>' (0x7fbfc4e44358) let randomRecipe: Dictionary = arrayOfRecipes[randomRecipeIndex] as! Dictionary<String,Any> return randomRecipe }

Swift下标错误

我相信它与可选项有关,但是我正在安全地解开sourceURL,所以我仍然不确定错误在哪里! 我试图访问一个JSON对象的数组的字典值。 但是,我仍然得到“无法find接受提供的参数'下标'重载。 这似乎很简单,但我似乎无法弄清楚! var dictTemp: NSDictionary! = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers, error: &localError) as? NSDictionary var finalURL: String // error line below if let sourceURL = dictTemp[0]["source"]["sourceUrl"] as? NSString { finalURL = sourceURL as String }

从sqlite读取unicode并创build一个NSString

我工作的iOS应用程序,我需要存储和从SQLite数据库中检索,具有下标的NSString的表示。 我可以在编译时用常量创build一个NSString: @ “BR \ u2082_CCl \ u2084” 是2个下标,是4个下标。 什么即时存储在SQLite数据库是: “BR \ u2082_CCl \ u2084” 但是我不知道该怎么做,将它重新转换成NSString。 数据从数据库中作为char *“Br \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'''''''删除额外的斜线在我的微弱实验中没有任何区别。 我需要一种方式让它回到NSString中 – 谢谢!

下标:使用string枚举访问我的字典值

我想要做这样的事情:用string枚举访问我的字典值。 我试图超载字典的下标,但没有成功。 访问字典: let district = address[JsonKeys.district] JsonKeys在哪里: enum JsonKeys: String { case key1 case key2 case key… } 我的下标过载如下: extension Dictionary where Key: StringLiteralConvertible, Value: AnyObject { subscript(index: FOJsonKeys) -> AnyObject { get { return self[ index.rawValue] as! AnyObject } } } 我收到以下消息: **Cannot subscript a value of type 'Dictionary<Key, Value>' with an index […]