infinitered / redpotion

We believe iPhone development should be clean, scalable, and fast with a language that developers not only enjoy, but actively choose. With the advent of Ruby for iPhone development the RubyMotion community has combined and tested the most active and powerful gems into a single package called RedPotion
MIT License
233 stars 40 forks source link

Documentation for using CDQ not working #130

Closed acoustep closed 9 years ago

acoustep commented 9 years ago

I'm not sure if this is an issue with RedPotion, CDQ or myself being a noob but after running through the CDQ tutorial here http://docs.redpotion.org/en/latest/cookbook/core_data/ I'm getting an error when trying to run the iOS simulator. So far I've uncommented the schema and generated the model files.

*** Starting simulator 2015-07-11 14:56:30.203 todo2[73446:1865241] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

I've tried this with the iOS 7.0 and the 8.4 simulator. I've even tried recreating a blank project to make sure it wasn't my own code causing it. The app works fine until I make the schema and model files.

I'm using the following gem versions:

RedPotion 1.3.0 ProMotion 2.4.2 CDQ 1.0.3

StackTrace:

*** First throw call stack:
(
    0   CoreFoundation                      0x0000000103283c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010093fbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001031508ca -[__NSArrayM insertObject:atIndex:] + 954
    3   todo2                               0x000000010000229e -[YKParser parseWithError:] + 708
    4   todo2                               0x000000010000151f +[YAMLKit loadFromString:] + 95
    5   todo2                               0x0000000100054e92 __unnamed_353 + 98
    6   todo2                               0x0000000100439abe rb_vm_dispatch + 6270
    7   todo2                               0x0000000100040f6c vm_dispatch + 1436
    8   todo2                               0x0000000100057753 rb_scope__load:__ + 211
    9   todo2                               0x0000000100439f29 rb_vm_dispatch + 7401
    10  todo2                               0x0000000100040f6c vm_dispatch + 1436
    11  todo2                               0x000000010005a0b0 rb_scope__initialize:__block__ + 208
    12  todo2                               0x000000010043b1df _ZL13vm_block_evalP7RoxorVMP11rb_vm_blockP13objc_selectormiPKm + 1119
    13  todo2                               0x000000010043b500 rb_vm_yield_args + 64
    14  todo2                               0x000000010042efbb rb_yield + 59
    15  todo2                               0x0000000100468979 rb_ensure + 25
    16  todo2                               0x0000000100439965 rb_vm_dispatch + 5925
    17  todo2                               0x0000000100040f6c vm_dispatch + 1436
    18  todo2                               0x00000001000593fe rb_scope__initialize:__ + 686
    19  todo2                               0x0000000100439f29 rb_vm_dispatch + 7401
    20  todo2                               0x00000001003992d4 rb_class_new_instance0 + 884
    21  todo2                               0x0000000100439965 rb_vm_dispatch + 5925
    22  todo2                               0x0000000100040f6c vm_dispatch + 1436
    23  todo2                               0x000000010005b0f3 rb_scope__default__ + 387
    24  todo2                               0x0000000100439f29 rb_vm_dispatch + 7401
    25  todo2                               0x0000000100040f6c vm_dispatch + 1436
    26  todo2                               0x000000010005cb7a rb_scope__initialize:__ + 186
    27  todo2                               0x0000000100439f29 rb_vm_dispatch + 7401
    28  todo2                               0x00000001003992d4 rb_class_new_instance0 + 884
    29  todo2                               0x0000000100439965 rb_vm_dispatch + 5925
    30  todo2                               0x0000000100040f6c vm_dispatch + 1436
    31  todo2                               0x00000001000ab319 rb_scope__models__ + 153
    32  todo2                               0x0000000100439f29 rb_vm_dispatch + 7401
    33  todo2                               0x0000000100040f6c vm_dispatch + 1436
    34  todo2                               0x00000001000ca38e rb_scope__cdq:__ + 990
    35  todo2                               0x0000000100439f29 rb_vm_dispatch + 7401
    36  todo2                               0x0000000100040f6c vm_dispatch + 1436
    37  todo2                               0x00000001000ce5d3 rb_scope__cdq:__ + 163
    38  todo2                               0x0000000100439f29 rb_vm_dispatch + 7401
    39  todo2                               0x0000000100040f6c vm_dispatch + 1436
    40  todo2                               0x00000001000cd437 rb_scope__inherited:__ + 135
    41  todo2                               0x0000000100439f29 rb_vm_dispatch + 7401
    42  todo2                               0x000000010033c683 rb_class_inherited + 275
    43  todo2                               0x0000000100460778 rb_vm_define_class + 1016
    44  todo2                               0x00000001003216f0 rb_scope1 + 112
    45  todo2                               0x0000000100321a55 MREP_D03103273A2A47B99E820C70C5455622 + 677
    46  todo2                               0x0000000100048fb1 RubyMotionInit + 2113
    47  todo2                               0x0000000100049045 main + 85
    48  libdyld.dylib                       0x0000000104615145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Any ideas if I'm doing something wrong?

squidpunch commented 9 years ago

I could be wrong but from what I recall.

If you've ran it on the simulator and then changed schema files you need to do a hard reset on your simulator. Either 'reset content and settings on the menu' or using the new clear gem.

Any schema that gets included in an app and then pushed to a device or simulator cannot be changed you need to bump it up with a migration. That being said what @kemiller suggested to me was you can change while in dev (but you will need to reset the simulator when changed) but once you push a release that may be on a device that file must remain as is and a migration needs added.

markrickert commented 9 years ago

Yeah, just use my reset-sim gem (included in newclear) to reset everything and start over again from scratch whenever i make a change to the schema.

Try that and let us know if that fixes the problem. If not, we'll keep digging :)

acoustep commented 9 years ago

I've just tried both rake newclear and "Resent Content and Settings..." and I'm receiving the same error still:

2015-07-11 18:38:29.914 todo2[24678:2332632] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

I've also tried updating app.sdk_version and app.deployment_target from 7.1 to 8.4 but I'm still getting the error.

Thank you for helping :)

markrickert commented 9 years ago

So your error: __NSArrayM insertObject:atIndex: seems like you're trying to do something to an array, like adding to it. Can you post some relevant code? It doesn't seem to be giving you a line number for the error.

acoustep commented 9 years ago

This is what I've been trying to find. Here are the files that I've edited:

schemas/0001_intiial.rb

schema "0001 initial" do

  # Examples:
  #
  entity "Person" do
    string :name, optional: false

    has_many :posts
  end

  entity "Post" do
    string :title, optional: false
    string :body

    datetime :created_at
    datetime :updated_at

    has_many :replies, inverse: "Post.parent"
    belongs_to :parent, inverse: "Post.replies"

    belongs_to :person
  end

end

app/models/person.rb

class Person < CDQManagedObject

end

app/models/post.rb

class Post < CDQManagedObject

end

app/screens/home_screen.rb

class HomeScreen < PM::Screen
  title "Your title here"
  stylesheet HomeScreenStylesheet

  def on_load
    set_nav_bar_button :left, system_item: :camera, action: :nav_left_button
    set_nav_bar_button :right, title: "Right", action: :nav_right_button

    @hello_world = append!(UILabel, :hello_world)
  end

  def nav_left_button
    mp 'Left button'
  end

  def nav_right_button
    mp 'Right button'
  end

  # You don't have to reapply styles to all UIViews, if you want to optimize, another way to do it
  # is tag the views you need to restyle in your stylesheet, then only reapply the tagged views, like so:
  #   def logo(st)
  #     st.frame = {t: 10, w: 200, h: 96}
  #     st.centered = :horizontal
  #     st.image = image.resource('logo')
  #     st.tag(:reapply_style)
  #   end
  #
  # Then in will_animate_rotate
  #   find(:reapply_style).reapply_styles#

  # Remove the following if you're only using portrait
  def will_animate_rotate(orientation, duration)
    find.all.reapply_styles
  end
end

It's a fresh project so there isn't much else to show, I can put the whole thing on Github if you think it will help.

I may try it running through it on my old Mac and see if I get the same issue.

squidpunch commented 9 years ago

Yeah if you can push to github I could clone and help debug, assuming mark doesn't beat me to it :)

acoustep commented 9 years ago

Here's the code: https://github.com/acoustep/rptodo

Thank you for taking a look, I've just made a fresh app on my old Mac and I'm getting the same issue.

At this point I'm hoping I haven't missed something incredibly obvious.

These are the step's I'm doing:

markrickert commented 9 years ago

So it looks like this might be some kind of CDQ error. I was able to reproduce your steps exactly and get the isssue. Perhaps @kemiller could chime in. I see a few commits in master regarding YAML stuff, but I get a different error when pointing the gemfile to github.

*\ Terminating app due to uncaught exception 'NameError', reason: 'config.rb:38:in `block in initialize:': uninitialized constant CDQ::CDQConfig::YAML (NameError)

Not sure why this isn't working out of the box.

squidpunch commented 9 years ago

@acoustep @markrickert ill pull it down and try and poke around soon too - thanks for bringing this up @acoustep !

kemiller commented 9 years ago

I over-fixed the YAML issue. Try again now.

acoustep commented 9 years ago

I've updated to CDQ 1.0.6 from master and now I'm getting the same error as @markrickert.

markrickert commented 9 years ago

This fix should be a temporary workaround while we fix the issue once and for all in CDQ: https://github.com/infinitered/cdq/issues/105#issuecomment-120950301

once and for all

acoustep commented 9 years ago

Haha, finally it works! Thank you for all of your help :)