我想确定一个字符串的书写方向,这样我就可以在CALayer中正确地呈现从右到左的语言,例如阿拉伯语.
所以我有这个方法
+(UITextAlignment)alignmentForString:(NSString *)astring
{
UITextView *text = [[UITextView alloc] initWithFrame:CGRectZero];
text.text = astring;
if ([text baseWritingDirectionForPosition:[text beginningOfDocument] inDirection:UITextStorageDirectionForward] == UITextWritingDirectionRightToLeft) {
return UITextAlignmentRight;
}
return UITextAlignmentLeft;
}
Run Code Online (Sandbox Code Playgroud)
工作正常,但感觉有点沉重只是为了发现哪种方式来调整我的文本,特别是在drawInContext中调用它(尽管相对不频繁).
是否有一种较轻的方法来确定给定字符串的书写方向,或者我应该在过早优化的基础上坚持这一点.它必须是iOS 5友好的.
以下是我的枚举
enum HomeDataType: String, CaseIterable {
case questions = "questions"
case smallIcons = "smallIcons"
case retailers = "retailers"
case products = "products"
case banners = "banners"
case single_product = "single_product"
case single_retail = "single_retail"
case categories = "categories"
case airport = "All_Airport"
case single_banner = "single_banner"
case none = "none"
}
Run Code Online (Sandbox Code Playgroud)
想要检查枚举中是否存在某个值?怎么做?
首先,我有一个 Could not build module Foundation
试图通过设置Enable Modules (C and Objective-C)来解决这个问题NO
在另一个构建后,我得到了这些奇怪的错
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_EAGLContext", referenced from:
objc-class-ref in EZAudioPlotGLKViewController-11ED1EEF7D7801BD.o
"_OBJC_CLASS_$_GLKBaseEffect", referenced from:
objc-class-ref in EZAudioPlotGLKViewController-11ED1EEF7D7801BD.o
"_OBJC_CLASS_$_GLKViewController", referenced from:
_OBJC_CLASS_$_EZAudioPlotGLKViewController in EZAudioPlotGLKViewController-11ED1EEF7D7801BD.o
"_OBJC_CLASS_$_NSEntityDescription", referenced from:
objc-class-ref in JSONModel+CoreData.o
"_OBJC_CLASS_$_NSManagedObject", referenced from:
l_OBJC_$_CATEGORY_NSManagedObject_$_JSONModel in JSONModel+CoreData.o
objc-class-ref in JSONModel+CoreData.o
"_OBJC_METACLASS_$_GLKViewController", referenced from:
_OBJC_METACLASS_$_EZAudioPlotGLKViewController in EZAudioPlotGLKViewController-11ED1EEF7D7801BD.o
"_SSLClose", referenced from:
-[GCDAsyncSocket closeWithError:] in GCDAsyncSocket.o
"_SSLCopyPeerTrust", referenced from:
-[GCDAsyncSocket ssl_continueSSLHandshake] in GCDAsyncSocket.o
"_SSLCreateContext", referenced from:
-[GCDAsyncSocket ssl_startTLS] in GCDAsyncSocket.o …Run Code Online (Sandbox Code Playgroud) 我有三个数组,priceArray,nameArray和discountArray.我在tableView中显示这些数组值.每个单元格都有价格,名称,折扣.
我想通过Price Low to High对列表进行排序,反之亦然,nameArray和discountArray中的项目需要根据价格排序进行排序.
同样,我希望按名称从AZ排序,反之亦然,并相应地对价格和折扣进行排序.
1 cell -- 20,xxx,10%
2 cell -- 10,zzz,10%
3 cell -- 150,aaa,0%
4 cell -- 100,hhh,15%
By Price Low to High
10,zzz,10%
20,xxx,10%
100,hhh,15%
150,aaa,0%
By Name A-Z
150,aaa,0%
100,hhh,15%
20,xxx,10%
10,zzz,10%
Run Code Online (Sandbox Code Playgroud)
帮我这样排序.