我在使用NSDictionaryCoreData模型中获取对象时遇到问题.
let moc:NSManagedObjectContext = SwiftCoreDataHelper.managedObjectContext()
let results:NSArray = SwiftCoreDataHelper.fetchEntities(NSStringFromClass(Notificatie), withPredicate: nil, managedObjectContext: moc)
for notificatie in results
{
let singleNotificatie:Notificatie = notificatie as Notificatie
let notDict:NSDictionary = ["title":notificatie.title, "fireDate":notificatie.fireDate]
}
Run Code Online (Sandbox Code Playgroud)
Cannot convert the expression's type 'NSDictionary' to type 'StringLiteralConvertible'
问题出在词典中.
为什么我不能将String转换为获取对象?有解决方案吗
我在swift项目中有一个'pickerView'对象.我确实理解Objective-c中的代码,但我不确定如何在Swift中实现它.
Objc方法
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
switch (component)
{
case 0://Week
return 7;
case 1://Hour
return 24;
default://Minutes
return 60;//or 7;(10 by 10) //or 13;(5 by 5)
}
}
Run Code Online (Sandbox Code Playgroud)
我只是不确定如何为titleForRow函数实现switch语句.所以stringWithFormat:@"%.2ld",(long)row问题就在于此.
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
switch (component)
{
case 0://Week
return _dayOfWeek[row];
case 1://Hour
return [NSString stringWithFormat:@"%.2ld",(long)row];
default://Minutes
return [NSString stringWithFormat:@"%.2ld",(long)row];//or ,row*10] //or ,row*5]
}
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我.
问候,达克斯