首页 \ 问答 \ 将NSManagedObjects添加到一对多关系中(Adding NSManagedObjects to a one-to-many relationship)

将NSManagedObjects添加到一对多关系中(Adding NSManagedObjects to a one-to-many relationship)

我有很多关系,例如一个学生有很多课程。

为什么在运行以下代码时_classes中没有新的Cls对象? 然而,当我关闭应用程序并重新打开它时。

作为一个后续问题,如何在添加新的类之后立即获取新的类列表?

NSMutableSet* classes = [student mutableSetValueForKey:@"classes"];
NSManagedObject* cls = [NSEntityDescription insertNewObjectForEntityForName:@"Cls" inManagedObjectContext:context];
[cls setValue:name forKey:@"name"];
[student addClassesObject:cls];

NSError* err;
[context save:&err];

NSMutableSet* _classes = [student mutableSetValueForKey:@"classes"];

这就是我的addClassesObject:操作的样子(由XCode自动生成)

- (void)addClassesObject:(Cls*)cls
{

}

谢谢!


I have a to-many relationship, e.g. A student has many classes.

Why is it when I run the following code _classes does NOT have the new Cls object in it? Yet when I close the app and reopen it does.

And as a follow up question, How would I get the new list of classes right after adding adding a new one?

NSMutableSet* classes = [student mutableSetValueForKey:@"classes"];
NSManagedObject* cls = [NSEntityDescription insertNewObjectForEntityForName:@"Cls" inManagedObjectContext:context];
[cls setValue:name forKey:@"name"];
[student addClassesObject:cls];

NSError* err;
[context save:&err];

NSMutableSet* _classes = [student mutableSetValueForKey:@"classes"];

And this is what my addClassesObject: operation looks like (auto generated by XCode)

- (void)addClassesObject:(Cls*)cls
{

}

Thank you!


原文:https://stackoverflow.com/questions/10989983
更新时间:2022-04-02 18:04

最满意答案

你的正则表达式中的第一个问题是“下一个标题探测器”( (?:^\s*#*\s*\w+.*\n(?:\s*[-=]*\s*\n)?|\z) )会匹配``! 所以它匹配你的标题之后的第一个空字符串(因为组捕获是非贪婪的)并且让你的捕获空着。 第二个问题是,您只能匹配以#Stuff的“Stuff”开头的标题,而不是模式

Stuff
=====

最后,由于您捕获了下一个标题,因此无法正确地连续使用“Stuff”标题。

这里有一个解决你的正则表达式的建议:
^(?<header>\s*#+\s*Stuff.*|\s*Stuff.*\n\s*(?:-{2,}|={2,}))\n(?<content>[\W\w]*?)(?=^(?:\s*#+|.*\n\s*(?:-{2,}|={2,}\s*\n))|\z)
要小心Ruby不完全是PCRE,所以在Rubular上进行测试更加准确,虽然它比Regex101上的测试更不方便用户使用


The first issue in your regex is that the "next title detector" ((?:^\s*#*\s*\w+.*\n(?:\s*[-=]*\s*\n)?|\z)) will match ``! So it matches the first empty string right after your title (since the group capture is non-greedy) and leaves your capture empty. The second issue is that you only match titles starting by "Stuff" of the form # Stuff, not the pattern

Stuff
=====

And lastly, since you capture the next header, you can't correctly handly successive "Stuff" headers.

Here's a proposal to fix your regex:
^(?<header>\s*#+\s*Stuff.*|\s*Stuff.*\n\s*(?:-{2,}|={2,}))\n(?<content>[\W\w]*?)(?=^(?:\s*#+|.*\n\s*(?:-{2,}|={2,}\s*\n))|\z)
Be careful that Ruby is not exactly PCRE, so it's more accurate to make tests on Rubular, though it's less user-friendly than tests on Regex101

相关问答

更多
  • 这将取决于你正在使用哪个降价插件,有很多来自快速谷歌搜索。 您必须在线查找您正在使用的特定文档,或者查看源文件,如果必须,请查看是否开源修改。 或者只是找到另一个允许该功能。 编辑:似乎django使用python-markdown(http://www.freewisdom.org/projects/python-markdown/),从快速看它似乎不支持只指定特定的格式选项。 但是它似乎很容易扩展,所以如果你写一个扩展,你可以在django中使用它,如下所示: {{ string|markdown:"e ...
  • 当他们做一件清楚的事情时,正则表达式最有效。 如果您有多个条件,那么您的代码通常应该通过将处理划分为多个步骤来反映出来。 在这种情况下,您有两个明确的步骤: 使用简单的正则表达式或其他逻辑来跳过消息的标题部分。 一旦您知道自己在内容中,请使用其他正则表达式来处理内容。 I've found a solution: regex = /(?])(?!.*\n(==|--))/i if @perm ...
  • 这是因为IoC正在解析CommonMarkConverter的依赖关系,特别是使用所有null属性实例化的Environment。 您可以通过使用Laravel特定集成解决此问题: https : //github.com/GrahamCampbell/Laravel-Markdown 或者您可以通过以下方式绑定和实例到服务容器: 在你的AppServiceProvider , register方法添加: $this->app->singleton('Markdown', function ($app) { ...
  • 如果您使用的是PowerShell 3或更高版本,请将-Raw添加到Get-Content的末尾。 默认情况下,Get-Content返回一个字符串数组,其中一个元素对应一行。 但是你想匹配一个字符串: $IniRegex = New-Object System.Text.RegularExpressions.Regex("\[[^\]\r\n]+](?:\r?\n(?:[^\[\r\n].*)?)*") $TestIni = Get-Content "C:\Test.ini" -Raw $Sections ...
  • 您的行中没有换行符。 在行的末尾, \只允许您将字符串放在多行中,但实际上并不包含换行符。 如果你明确地包含换行符,那么你的行首就会有太多空白,而最终会有一个
    块。 以下使用三重引号保留换行符: >>> import markdown
    >>> content = '''\
    ... Footnotes[^1] have a label[^@#$%] and the footnote's content.
    ... 
    ... [^1]: This is a footnote content.
    ... [^  ...
                                        
  • 你的正则表达式中的第一个问题是“下一个标题探测器”( (?:^\s*#*\s*\w+.*\n(?:\s*[-=]*\s*\n)?|\z) )会匹配``! 所以它匹配你的标题之后的第一个空字符串(因为组捕获是非贪婪的)并且让你的捕获空着。 第二个问题是,您只能匹配以#Stuff的“Stuff”开头的标题,而不是模式 Stuff ===== 最后,由于您捕获了下一个标题,因此无法正确地连续使用“Stuff”标题。 这里有一个解决你的正则表达式的建议: ^(?
    \s*#+\s*Stuff.*|\s ...
  • 您所要做的就是获取降价文本并解析它。 然后把它放在某个地方。 你甚至可以把它放回原处。 var markdown = $('#markdown-content').html(); var html = md.render(markdown); $('#output').html(html); All you have to do is get the markdown text and parse it. Then put it somewhere. You could even put it back ...
  • Redcarpet的输出是HTML。 它在浏览器中的显示方式取决于您如何设置此HTML样式,并且或多或少独立于源标记中的间距。 您给出的降价产生以下HTML:

    We're looking for someone with…

    • Significant Rails experience
    • Good communication skills (recommended)

    You should be located near: ...

  • 我找到了正确的正则表达式字符串 。 '((?#+)\s*(?.+))|((?[\w|\d|\s|-]+)\n(?[-|=]{2,}))'匹配我想要的所有附件。 我会告诉你这个功能的最新消息,也许它会派上用场。 我想,我将拆分md以排除受防护的代码块。 更新1 好吧,我重做了这个字符串,因为它不如我最初那么好。 现在我有(?[^\n\r]+)\n(?[-|=]{2,})$|^((?#{1 ...
  • markdown方法需要一个字符串。 如果用nil调用它,则会抛出此错误。 您可能希望将代码更改为类似的值以处理nil值: def markdown(string) @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true, fenced_code_blocks: true) @markdown.render(string.to_s) end 此外 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)