Since our theme is cars here, we’ll stick with three simple attributes: year, make, and model: Next it’s time to actually add attributes to the model. For our example, let’s name it “CarModel”: Give the data model file a name that seems to fit your situation. Once the framework project has been created, we’re set to drop in a new Data Model file from Xcode’s new file dialog (File -> New -> File…). In keeping with Apple’s “_Kit” theme, we’ll name our framework “CarKit”: Typically we stay in the realm of the “iOS Application” project templates, but if you click “Framework & library”, you’ll see the option to create a new Cocoa Touch Framework: To get started with creating a Swift framework, begin with Xcode’s New Project dialog (File -> New -> Project…). CarKit + Carz Core Data Framework Example.I’m providing a completed CarKit + Carz package for you to look at over at GitHub: We won’t actually dive into the Mac project, but one could imagine the process being very similar for importing CarKit into the Mac application when it came time to build that one. The other will be a single view iOS application. We’ll be creating two Xcode projects during this walkthrough: One will be the framework and will be called “CarKit”. The app will target car enthusiasts everywhere – we will empower car fanatics to manage of a list of their favorite cars. The only difference between the apps will be the target platform. Our team is building an iOS app and a Mac app and the underlying data model will be exactly the same between them. Our working example for this walkthrough will be the following: Whatever the case may be, wouldn’t it be awesome to design the Core Data model once and share it between your projects? Maybe you’re building several iOS apps that have different user interfaces but share some underlying persistence-layer models. Perhaps you’re working on an iOS + Mac app combination and the data model for each is identical. Not only can we share code between projects, we can also share Core Data models between projects by utilizing frameworks! With the introduction of dynamic frameworks in iOS 8, a world of possibility opened up for iOS developers to achieve some pretty cool re-use scenarios, one of which we’re going to dive into today. We strive for it though, because in the long run, it makes maintaining the code far, far easier than if we just settled for copying and pasting. Code re-use is a powerful thing, but it’s not always easy to pull off.
0 Comments
Leave a Reply. |