我有一个Core Data类"Meeting",其中包含一个属性"date",我希望使用NSFetchedResultsController在TableView中显示该属性.会议应按两种方式分类:首先,应在同一部分对一个月的所有会议进行总结,并按日期对一个月/每个部分的所有会议进行排序.
NSComparisonResult (^periodSortBlock)(id, id) = ^(id obj1, id obj2) {
NSLog(@"Debug");
NSDate *date1 = (NSDate *)obj1;
NSDate *date2 = (NSDate *)obj2;
// Pseudocode
Month *month = [Month monthWithDate:date1];
NSComparisonResult result = NSOrderedSame;
if ([Month date:date2 afterDate:month.end])
result = NSOrderedAscending;
else if ([Month date:date2 beforeDate:month.start])
result = NSOrderedDescending;
return result;
};
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Meeting"];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"SELF IN %@", self.meetings];
NSSortDescriptor *sectionByMonth = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:false comparator:periodSortBlock];
NSSortDescriptor *sortByDate = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:false];
fetchRequest.sortDescriptors = [NSArray arrayWithObjects:sectionByMonth, …Run Code Online (Sandbox Code Playgroud) 我正在将Windows Phone 8应用程序移植到Windows 8.1,并希望使用ApplicationData.Current.LocalSettings来存储/保留一些数据.除了一些String/Bool/Int值之外,我还希望存储一个(非常简单的)自定义类.
[DataContract]
public class MyClass {
[DataMember]
public double Property1;
[DataMember]
public int Property2;
[DataMember]
public int Property3;
[DataMember]
public bool Property4;
public int Total{
get { return Property2 + Property 3; }
}
}
}
Run Code Online (Sandbox Code Playgroud)
在WP 8上,我使用IsolatedStorageSettings.ApplicationSettings来存储设置而没有任何问题.即使我不使用DataContract/DataMember,它也能正常工作:
MyClass mySettings = new MyClass();
mySettings.Property2 = 1;
mySettings.Property2 = 2;
IsolatedStorageSettings.ApplicationSettings["mySettings"] = mySettings;
IsolatedStorageSettings.ApplicationSettings.Save();
MyClass loadedSettings = IsolatedStorageSettings.ApplicationSettings["mySettings"];
Debug.WriteLine(loadedSettings.Total); // == 3
Run Code Online (Sandbox Code Playgroud)
使用时,Win 8.1上的相同内容会导致序列化异常:
...
ApplicationData.Current.LocalSettings.Values["mySettings"] = mySettings;
Error trying to serialize the value to be written to …Run Code Online (Sandbox Code Playgroud) 我使用Nexus 5作为我的第一个Android应用程序的测试设备.当我通过USB将手机连接到我的PC时,它会在浏览器中弹出,我可以访问设备上的不同文件和文件夹(就像设备是USB记忆棒一样......).
我认为这些文件和文件夹代表External Storage我的应用程序存储的每个文件/文件夹External Storage也可以通过USB访问.
External Storage在我的应用程序中创建文件/文件夹没有问题,这些文件在可以通过USB访问的文件和文件夹中不可见:
public static File getAppPuplicExternalStorageDir() {
File appDir = null;
try {
appDir = new File(Environment.getExternalStorageDirectory(), "MyApp");
appDir.mkdirs();
}
catch (Exception e) { }
return appDir;
}
...
File noMediaFile = new File(getAppPuplicExternalStorageDir(), ".nomedia");
noMediaFile.createNewFile();
...
Run Code Online (Sandbox Code Playgroud)
这段代码完美无缺.我可以测试文件是否存在,删除文件,创建其他文件等没有任何问题.
当我检查appDir时,它有路径/storage/emulated/0/MyApp/.一切正常,除了通过USB看不到这个文件夹.
外部存储和通过USB访问的文件/文件夹之间有区别吗?用户应该能够将文件下载到他的PC.如何设法通过USB显示我的文件?
我正在开发我的第一个 Symfony 5 项目,并且很难使用内置的MailerInterface. 我之前曾在 Symfony 3 中使用过 Swift Mailer,以前从未遇到过类似的问题。
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\MailerInterface;
...
class SomeController extends AbstractController {
public someAction(Request $request, MailerInterface $mailer) {
...
$email = (new TemplatedEmail())
->from(new Address('address@example.com', 'My Symfony Mail'))
//->to($user->getEmail())
->to('receiver@example.com')
->subject('Subject')
->htmlTemplate('email.html.twig');
$mailer->send($email);
}
}
// .env
#MAILER_DSN=smtp://user:pass@smtp.example.com:25
MAILER_DSN=sendmail://default
Run Code Online (Sandbox Code Playgroud)
如果MAILER_DSN有一些格式错误,则会抛出异常并显示在 Symfony 调试器页面上,例如The "invaliddsn" mailer DSN must contain a scheme...因此,配置的 DSN 似乎smtp://user:pass@smtp.example.com:25是正确的。在其他邮件应用程序中使用相同的凭据、主机和端口没有问题。
但是,使用此代码时不会显示错误/异常,并且我根本没有收到任何邮件。当然,我已经仔细检查了日志(没有错误)、接收者垃圾邮件文件夹(什么也没有)。指定 SMTP 服务器或 sendmail 没有任何区别。
Symfony 文档仅解释如何处理异常,但在我的例子中没有抛出异常。
虽然关于 Symfony 中的邮件问题还有很多其他问题,但其中大多数都涉及较旧的 Swift Mailer …
我花了最近几天才第一次使用Core Plot.我花了一些时间弄清楚它是如何工作的,但我几乎可以实现我所寻找的所有功能.但有一件事我没有找到解决方案:
我正在使用两个轴上带有标签的XY图.plotAreaFrame有一个左边的填充,可以将plotArea向右移动,并为y轴标签创建一些空闲空间.只要标签不大,这样就可以正常工作,例如,对于高达100的值,但是如果y值变大,例如.10.0000,填充不足以显示完整的标签.
当然我可以使用更高的填充但是如果我只有很小的y值,这会浪费空间.
有没有办法根据标签自动调整填充?
我正在开发我的第一个iCloud应用程序.工作一段时间后,由于"UIDocumentStateSavingError",应用程序无法再访问UIManagedDocument.有没有办法真正找出发生了什么错误?
这是我创建UIManagedDocument的代码:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
iCloudURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (iCloudURL == nil) {
dispatch_async(dispatch_get_main_queue(), ^{
[self iCloudNotAvailable];
});
return;
}
iCloudDocumentsURL = [iCloudURL URLByAppendingPathComponent:@"Documents"];
iCloudCoreDataLogFilesURL = [iCloudURL URLByAppendingPathComponent:@"TransactionLogs"];
NSURL *url = [iCloudDocumentsURL URLByAppendingPathComponent:@"CloudDatabase"];
iCloudDatabaseDocument = [[UIManagedDocument alloc] initWithFileURL:url];
NSMutableDictionary *options = [NSMutableDictionary dictionary];
NSString *name = [iCloudDatabaseDocument.fileURL lastPathComponent];
[options setObject:name forKey:NSPersistentStoreUbiquitousContentNameKey];
[options setObject:iCloudCoreDataLogFilesURL forKey:NSPersistentStoreUbiquitousContentURLKey];
iCloudDatabaseDocument.persistentStoreOptions = options;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(documentContentsChanged:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification object:iCloudDatabaseDocument.managedObjectContext.persistentStoreCoordinator];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(documentStateChanged:) name:UIDocumentStateChangedNotification object:iCloudDatabaseDocument];
if ([[NSFileManager defaultManager] fileExistsAtPath:[iCloudDatabaseDocument.fileURL path]]) {
// This is …Run Code Online (Sandbox Code Playgroud) 我正在努力将Windows Phone 8应用程序移植到Windows应用商店8.1,我对Win 8.1上的页面导航如何工作感到困惑.它似乎与WP 8完全不同:
给定:PageA作为主页面和其他一些页面PageB. 导航:启动应用程序,向前导航到B并返回到A.
Windows Phone 8:
- Constructor of PageA
- PageA.OnNavigatedTo()...
- PageA was just created? Ok, create ViewModel
- Click some Button to navigate to PageB
- Creation of PageB + actual Navigation...
- Click some Button to navigate back to PageA
- PageA.OnNavigatedTo()...
- PageA was just created? No, use existing ViewModel
Run Code Online (Sandbox Code Playgroud)
Windows应用商店App 8.1:
- Constructor of PageA
- PageA.OnNavigatedTo()...
- PageA was just created? Ok, create ViewModel
- Click some …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的 Android 应用程序创建一个可绘制的简单图层列表。当我将 drawable 设置为 ImageView 的 src 时,它没有正确绘制:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="20dp">
<shape android:shape="oval">
<solid android:color="@color/dark_gray" />
</shape>
</item>
<item android:left="20dp">
<shape android:shape="oval">
<solid android:color="@color/dark_gray" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
只是两个椭圆形,彼此有点偏移。没什么特别的(只是一个测试),但它不起作用。
看来这android:left|right|bottom|top就是问题所在。如果我只使用这些命令中的一个,drawable 就会被正确绘制。如果使用两个或更多,则 ImageView 保持为空。
作品:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="20dp">
<shape android:shape="oval">
<solid android:color="@color/dark_gray" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="@color/dark_gray" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
不起作用(如第一个示例):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="..." >
<item android:top="20dp" android:left="20dp">
<shape android:shape="oval">
<solid android:color="@color/dark_gray" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
这里有什么问题? …
我正在将Symfony 2.8项目迁移到Symfony 3.4. 虽然整个过程非常简单,但我有一点绊倒了:
虽然显示的代码运行没有任何问题,Symfony 2.8但它Symfony 3.4以ContextErrorException. 代码来自“Catch all”控制器,该控制器处理对未被任何其他路由处理的 URL 的调用:
public function catchallAction(Request $request) {
$url = $_SERVER['REQUEST_URI'];
// Try to find a solution, e.g. by adding / replacing the locale
if (1 === preg_match('/(\/app_dev\.php)?(\/([a-z]{2}))?(((\/([^\/]+))?(\/[^?]+))(\?(.+))?)/', $url, $matches)) {
$this->logger->info('catchallAction');
$this->logger->info(" $url");
foreach ($matches as $key => $value)
$logger->info(" $key => $value");
$locale = (isset($matches[3]) ? $matches[3] : null);
$subdir = (isset($matches[7]) ? $matches[7] : null);
$path = $matches[5];
$query …Run Code Online (Sandbox Code Playgroud) 是否可以找到 iOS 项目中可用的所有本地化表?
背景:
在一个基于 Swift 的 iOS 项目中,我使用多个本地化.strings文件。例如,一个文件包含不同项目中使用的通用字符串,一个文件包含项目特定字符串等。
使用自定义本地化方法可以很好地工作,该方法检查是否在文件/表 A 中找到给定字符串,如果未找到翻译,则继续在文件/表 B 中搜索:
func localizedString(forKey key: String) -> String {
// Search in project specific, default file Localizable.strings
var result = Bundle.main.localizedString(forKey: key, value: nil, table: nil)
// If now translation was found, continue search in shared file "Common.strings"
if result == key {
result = Bundle.main.localizedString(forKey: key, value: nil, table: "Common")
}
if result == key {
result = Bundle.main.localizedString(forKey: key, value: nil, table: "OtherFile")
} …Run Code Online (Sandbox Code Playgroud)