Author Topic: Xcode 6 and mmBusinessObject  (Read 4299 times)

rtamesis

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Xcode 6 and mmBusinessObject
« on: September 19, 2014, 07:16:20 PM »
I'm getting some strange behavior with mmBusinessObject where the saveEntities method does not appear to be working properly. I tested my same code on both Xcode 5 and 6 on separate laptops, and while it saves my changes properly to the SQLite database on Xcode 5, it is not doing so on Xcode 6. I've tried cleaning it and deleting the built app from both the simulator and on my iPad, but it doesn't seem to solve the problem.

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #1 on: September 19, 2014, 08:35:45 PM »
Are you coding in Swift or Objective-C? I have updated mmBusinessObject to Swift for iOS 8 and Xcode 6 and can get you an early copy if you're interested.

All the best!
Kevin

rtamesis

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #2 on: September 19, 2014, 11:32:16 PM »
I'm still using Objective-C. I'll probably start learning Swift once I get the app that I've been working on for the last year and a half finished.
« Last Edit: September 19, 2014, 11:34:05 PM by rtamesis »

rtamesis

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #3 on: September 20, 2014, 11:55:32 AM »
On further testing, it looks like any changes aren't being saved until I actually quit my app and restart it again. After a user completes a quiz in my app, his or her grade is supposed to be saved to the database using the saveEntities method; I then reload the table listing the grades for different quizzes taken to display the new grade. This works perfectly when running the app on iOS 7, but in iOS 8 both in the simulator and on an iPad, the new grade is not seen until I actually quit the app and then reopen the app again. I don't know if Apple made an underlying change to Core Data in the way data is saved or not or if this is a bug on their part in iOS 8 itself, but I may have to just simply take this functionality out of the app I'm building if I can't find a workaround to it.
« Last Edit: September 20, 2014, 11:58:22 AM by rtamesis »

rtamesis

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #4 on: September 20, 2014, 03:23:07 PM »
Well once again I may have been a wee bit premature in saying that the problem lay with Core Data. I may have solved the problem by forcing the tableview to reload in the viewWillAppear: method of the tableViewController. Sorry for all the trouble.

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #5 on: September 21, 2014, 01:51:11 PM »
No problem...glad you were able to figure it out!

Kevin

idearm

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #6 on: November 05, 2014, 04:03:26 AM »
Kevin,

I have done some digging and decided to build my app using only Swift, but am having some difficulty figuring out how to rewrite the mmBusinessObject in Swift. Any suggestions? You presented a much more logical route in Book 3 and would prefer to stick to it.

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #7 on: November 05, 2014, 05:57:57 PM »
Sure...here's the version I'm releasing with the upcoming Swift book.

Note that this class uses generics, so here's what your ABusinessObject class needs to look like:

Code: [Select]
class ABusinessObject<T: NSManagedObject> : mmBusinessObject<T> {
   
    override init() {
        super.init()
        self.dbName = "YourDatabaseName"  // <-- Change this
    }
}

And you need to specify the associated entity for your app-specific business objects:

Code: [Select]
class AppCategory<T: AppCategoryEntity>: ABusinessObject<T> {
   
}

Note that you no longer need to set the entityClassName property in your business object classes. That's because you are already specifying the entity in the generic type <T: AppCategoryEntity>.

All the best!
Kevin

idearm

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #8 on: November 06, 2014, 03:22:43 AM »
This helps a ton, thanks!!

Looking forward to Book 4 as well!!

idearm

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Xcode 6 and mmBusinessObject
« Reply #9 on: November 06, 2014, 11:57:50 PM »
Hey Kevin,

Just to make sure I am understanding correctly. Within my Business Controller class there is no need for:

self.entityClassName = "EntityClassName"

Line of code because it has already been declared with the generic type similar to what you suggested? Therefore:

override init() {
     super.init()
}

Is all that I would need (for the time being) within my Business Controller class? Please correct me if I'm wrong.


Thank you so much for all of your help! I CANNOT wait to get my hands on Book 4 (granted I will be buying it through the iBooks Store)!!


Best Regards,