小编Pad*_*rom的帖子

Realm对象已被删除或无效

当我启动我的应用程序时,我执行API调用以查看是否有新数据可用.数据存储在我的本地Realm数据库中,其中一些数据显示在初始表视图控制器中.

API调用完成后,我会检查是否满足某些条件,要求我从数据库中删除一堆先前的数据,然后创建新对象.但是,当我删除旧数据时,我的应用程序崩溃时出现以下异常:

2015-08-06 11:56:32.057 MSUapp[19754:172864] *** Terminating app due to uncaught exception 'RLMException', reason: 'Object has been deleted or invalidated.'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010660cc65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x00000001083bdbb7 objc_exception_throw + 45
2   Realm                               0x0000000105b78e95 _ZL17RLMVerifyAttachedP13RLMObjectBase + 85
3   Realm                               0x0000000105b7878d _ZL10RLMGetLinkP13RLMObjectBasemP8NSString + 29
4   Realm                               0x0000000105b7c23e ___ZL17RLMAccessorGetterP11RLMProperty15RLMAccessorCodeP8NSString_block_invoke_12 + 46
5   MSUapp                              0x0000000105764867 _TFFC6MSUapp29FavoriteLeaguesViewController18generateLeagueListFS0_FT_T_U_FTCS_6LeagueS1__Sb + 39
6   MSUapp                              0x00000001057648eb _TTRXFo_oC6MSUapp6LeagueoS0__dSb_XFo_iS0_iS0__dSb_ + 27
7   libswiftCore.dylib                  0x0000000108674ae2 _TFSs14_insertionSortUSs21MutableCollectionType_USs13GeneratorType__Ss22BidirectionalIndexType_Ss18_SignedIntegerType_Ss33_BuiltinIntegerLiteralConvertible____FTRQ_GVSs5RangeQQ_5Index_RFTQQQ_9Generator7ElementS7__Sb_T_ + 1570
8   libswiftCore.dylib                  0x0000000108676682 _TFSs14_introSortImplUSs21MutableCollectionType_USs13GeneratorType__Ss21RandomAccessIndexType_Ss18_SignedIntegerType_Ss33_BuiltinIntegerLiteralConvertible_Ss16SignedNumberType_S3_____FTRQ_GVSs5RangeQQ_5Index_RFTQQQ_9Generator7ElementS8__SbSi_T_ + 1250 …
Run Code Online (Sandbox Code Playgroud)

realm ios swift

50
推荐指数
7
解决办法
3万
查看次数

传递给函数的参数必须是可调用的,给定数组

我正在尝试在集合中的每个元素上运行一个方法.它是驻留在同一个类中的对象方法:

protected function doSomething()
{
    $discoveries = $this->findSomething();
    $discoveries->each([$this, 'doSomethingElse']);
}

protected function doSomethingElse($element)
{
    $element->bar();
    // And some more
}
Run Code Online (Sandbox Code Playgroud)

如果我在调用之前Collection::each使用检查is_callable([$this, 'doSomethingElse'])它返回true,那么显然它是可调用的.然而,调用本身会引发异常:

类型错误:参数1传递给Illuminate\Support\Collection :: each()必须是可调用的,给定数组,在第46行中调用--- .php

尝试调用的方法可以在这里找到.

我通过传递一个本身只是调用该函数的闭包来绕过这个,但这肯定是一个更清洁的解决方案,我无法找出它抛出错误的原因.

php collections laravel

16
推荐指数
2
解决办法
8208
查看次数

Prolog 从原子构建规则

我目前正在尝试通过 Prolog 解释用户输入的字符串。我正在使用我在互联网上找到的代码,它将字符串转换为原子列表。

"Men are stupid." => [men,are,stupid,'.'] % Example
Run Code Online (Sandbox Code Playgroud)

由此我想创建一个规则,然后可以在 Prolog 命令行中使用它。

% everyone is a keyword for a rule. If the list doesn't contain 'everyone'
% it's a fact.

% [men,are,stupid]
% should become ...
stupid(men).

% [everyone,who,is,stupid,is,tall]
% should become ...
tall(X) :- stupid(X).

% [everyone,who,is,not,tall,is,green]
% should become ...
green(X) :- not(tall(X)).

% Therefore, this query should return true/yes:
?- green(women).
true.
Run Code Online (Sandbox Code Playgroud)

我不需要任何超级花哨的东西,因为我的输入将始终遵循一些规则,因此只需要根据这些规则进行分析。

我已经考虑了大约一个小时,但没有想到任何重要的事情,所以我无法向您提供我迄今为止尝试过的内容。谁能把我推向正确的方向?

prolog tokenize

5
推荐指数
1
解决办法
558
查看次数

Laravel Eloquent找到复合键

我最近开始使用Laravel 5作为框架.到目前为止,一切都是完全直截了当的,与它一起工作真的很棒.然而,目前我遇到了一些关于我的Eloquent模型的麻烦.

数据库表reports具有以下模式:

| id | group_id | score | ... |
Run Code Online (Sandbox Code Playgroud)

group_id是引用该groups表的外键.此表中的主键是的复合idgroup_id.id也不是自动增加,因为它是我用来更容易内部处理的外部ID.

每个外部id可以为我的每个组一次出现,并且每个外部id都有不同的分数,因此是复合主键.

访问我的一个页面时,我想从外部数据源获取最新记录,并将它们与相应的数据库行匹配.如果它们不存在,我想创建它们.

我目前的这条路线代码是:

public function showReports ($id)
{
   $group = Group::findOrFail($id);

   foreach ($group->getLatestReports(20) as $reportElement)
   {
       $report = Report::find($reportElement['id']);
       if (is_null($report))
       {
           $report = new Report;
           // Fill values ...
           $report->save();
       }
   }
}
Run Code Online (Sandbox Code Playgroud)

这显然不能按预期工作,因为它只查找id
(::find($reportElement['id'])),而不是group_id.像往常一样我的问题,答案可能非常简单,但我现在似乎无法找到它.

php laravel eloquent laravel-5

4
推荐指数
1
解决办法
1万
查看次数

SVG textPath 在 Safari 中不起作用

我正在尝试通过内联 SVG 在图像上覆盖弯曲的文本。它在 Chrome 中运行良好,但 iOS 和桌面上的 Safari 无法呈现文本。

<svg viewBox="0 0 580 472" width="580" height="472" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
    <defs>
        <path id="curvedPath" d="M123.9,309.87s55.27,20.4,148.06,23.54c99.49,3.37,153.33-16.68,153.33-16.68"></path>
        <style type="text/css">
            #text {
                font-size: 24px;
                text-align: center;
                text-anchor: middle;
                fill: rgba(0,0,0,0.8);
            }
        </style>
    </defs>

    <image x="0" y="0" width="580" height="472" xlink:href="https://www.silvity.de/out/pictures/master/product/1/gravur-armband-swarovski-kristall-rosegold-schwarz-111106601.jpg"></image>

    <text id="text" class="Philosopher">
        <textPath href="#curvedPath" startOffset="50%" id="textcontent">Foobar StackOverflow</textPath>
    </text>
</svg>
Run Code Online (Sandbox Code Playgroud)

此代码段在 Chrome 中显示文本“Foobar StackOverflow”,但在 Safari 中不显示。

路径的曲线无关紧要,直线 ( M10.100,L100.100) 也不起作用。我可以让文本显示的唯一方法是将其直接嵌入到text标签中,例如<text id="...">Foobar StackOverflow</text>,这显然不是我想要的。

textPath在 Safari SVG中使用有什么限制吗?我怎样才能让它在两个浏览器中正确呈现?

html safari svg

3
推荐指数
1
解决办法
1067
查看次数

标签 统计

laravel ×2

php ×2

collections ×1

eloquent ×1

html ×1

ios ×1

laravel-5 ×1

prolog ×1

realm ×1

safari ×1

svg ×1

swift ×1

tokenize ×1