我想在一个链式命令中拆分并在字符串中进行替换.这是我的示例,包括错误消息:
>> filebase
=> "Ueki_-_Hello_World"
>> filebase.split("_-_").gsub("_"," ")
NoMethodError: private method `gsub' called for ["Ueki", "Hello_World"]:Array
from (irb):16
Run Code Online (Sandbox Code Playgroud)
当我将"split"的结果保存在临时变量中时,它可以工作.我真的需要吗?
我正在使用NSOperationQueue排队并调用多个地理编码位置查找.我想在所有异步运行的查找完成后调用完成方法.
-(void)geocodeAllItems {
NSOperationQueue *geoCodeQueue = [[NSOperationQueue alloc]init];
[geoCodeQueue setName:@"Geocode Queue"];
for (EventItem *item in [[EventItemStore sharedStore] allItems]) {
if (item.eventLocationCLLocation){
NSLog(@"-Location Saved already. Skipping-");
continue;
}
[geoCodeQueue addOperationWithBlock:^{
NSLog(@"-Geocode Item-");
CLGeocoder* geocoder = [[CLGeocoder alloc] init];
[self geocodeItem:item withGeocoder:geocoder];
}];
}
[geoCodeQueue addOperationWithBlock:^{
[[NSOperationQueue mainQueue]addOperationWithBlock:^{
NSLog(@"-End Of Queue Reached!-");
}];
}];
}
- (void)geocodeItem:(EventItem *)item withGeocoder:(CLGeocoder *)thisGeocoder{
NSLog(@"-Called Geocode Item-");
[thisGeocoder geocodeAddressString:item.eventLocationGeoQuery completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
NSLog(@"Error: geocoding failed for item %@: %@", item, error); …Run Code Online (Sandbox Code Playgroud) 我正在调用一个设置状态的方法,在本例中是animateState.状态参数可以是定义的集合之一:例如"hide","show","active","inactive".所以它不仅仅是BOOL,而且比开放的NSString更加独特.
目前我通过使用NSString解决这个问题,并使用其isEqual方法检查状态.它工作但不理想.
-(void) animateState:(NSString*)state{
if ([state isEqual:@"hide"]){
...
} else if ([state isEqual:@"show"]){
...
} else if ([state isEqual:@"active"]){
...
} else if ([state isEqual:@"inactive"]){
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何限制参数并最终使if/switch检查更有效?这种情况的最佳做法是什么?
我已经找到了很多方法,但没有可行的解决方案.这是我尝试过但没有用的东西.
(1)简单地调用primaryLanguage()
UITextInputMode().primaryLanguage
Run Code Online (Sandbox Code Playgroud)
→总是返回nil: - /
(2)订阅UITextInputCurrentInputModeDidChangeNotification通知
override func viewDidLoad() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeInputMode:", name: UITextInputCurrentInputModeDidChangeNotification, object: nil)
}
func changeInputMode(sender : NSNotification) {
...?!
}
Run Code Online (Sandbox Code Playgroud)
通知已被触发,但我不清楚如何从通知中提取当前语言信息.
(3)使用activeInputModes()
let localeIdentifier = UITextInputMode.activeInputModes().first as? UITextInputMode
var locale:NSLocale = NSLocale(localeIdentifier: localeIdentifier.primaryLanguage!)
println("Input Mode Language \(localeIdentifier.primaryLanguage!)")
Run Code Online (Sandbox Code Playgroud)
这始终提供所有可用键盘的相同阵列,没有关于实际活动键盘的信息.
如何获取当前活动键盘的NSLocale?
我想在我的应用程序的触摸栏中显示一个可滚动的按钮列表,类似于Safari在键入地址时显示收藏夹的方式.
滚动视图似乎不是标准的TouchBar控件之一.您使用哪种控件?
我在Mac OS X上运行PHP 5.4.24.看起来像
<?php
Run Code Online (Sandbox Code Playgroud)
被接受为包含脚本但不包含脚本的PHP标记
<?
Run Code Online (Sandbox Code Playgroud)
怎么能改变?如果两者都能奏效将会很好.