0
Objective-C代碼試圖轉換到斯威夫特2:轉換爲斯威夫特2
-(void)dataLoadMethod
{
//NSLog(@"data load method is displaying")
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH.mm"];
NSString *strCurrentTime = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"Check float value: %.2f",[strCurrentTime floatValue]);
if ([strCurrentTime floatValue] >= 18.00 || [strCurrentTime floatValue] <= 6.00){
UINavigationController *navigationController = (UINavigationController *)[self.storyboard instantiateViewControllerWithIdentifier:@"NightSkin"];
[self presentViewController:navigationController animated:YES completion:nil];
}else{
UINavigationController *navigationController = (UINavigationController *)[self.storyboard instantiateViewControllerWithIdentifier:@"DaySkin"];
[self presentViewController:navigationController animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
});
這是斯威夫特到目前爲止我的代碼:
func loadCreate() {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "hh:mm"
dateFormatter.dateStyle = .ShortStyle
var strCurrentTime = dateFormatter.stringFromDate(NSDate())
print(dateFormatter.stringFromDate(NSDate()))
NSLog("Check float value: %.2f", strCurrentTime)
if ([strCurrentTime Float] >= 18.00 || [strCurrentTime Float] <= 6.00) {
NSBundle.mainBundle().loadNibNamed("DaySkin", owner: self, options: nil)
self.addSubview(self.view);
}
else {
NSBundle.mainBundle().loadNibNamed("NightSkin", owner: self, options: nil)
self.addSubview(self.view);
}
}
從if語句有麻煩;用double賦值floatValue並顯示ViewController。
任何幫助,不勝感激。
非常感謝。但是,現在我得到'使用未解析的標識符作爲自己'的錯誤。 – Bux
@Bux你在哪裏放這個代碼呢?我相信這應該是裏面的一些'UIViewController'在那裏,你一定會有的'self' – KlimczakM
目標C我把它: - } - (無效){loadCreate [自performSelectorInBackground:@selector(dataLoadMethod) withObject :零]; (IBAction)Wx:(id)sender { {self-loadCreate]; } } – Bux