Timeline
Timeline is a simple photo sharing service. Students will bring in many concepts that they have learned, and add more complex data modeling, Image Picker, CloudKit, and protocol-oriented programming to make a Capstone Level project spanning multiple days and concepts.
Install / Use
/learn @DevMountain/TimelineREADME
Timeline
Level 3
Timeline is a simple photo sharing service. Students will bring in many concepts that they have learned, and add more complex data modeling, Image Picker, CloudKit, and protocol-oriented programming to make a Capstone Level project spanning multiple days and concepts.
Most concepts will be covered during class, others are introduced during the project. Not every instruction will outline each line of code to write, but lead the student to the solution.
Students who complete this project independently are able to:
Part One - Project Planning, Model Objects, and Controllers
- follow a project planning framework to build a development plan
- follow a project planning framework to prioritize and manage project progress
- implement basic data model
- use staged data to prototype features
Part Two - Apple View Controllers, Search Controller, Container Views
- implement search using the system search controller
- use the image picker controller and activity controller
- use container views to abstract shared functionality into a single view controller
Part Three - Basic CloudKit: CloudKitManager,
- Check CloudKit availability
- Save data to CloudKit
- Fetch data from CloudKit
- Query data from CloudKit
Part Four - Intermediate CloudKit: Subscriptions, Push Notifications, Automatic Sync
- use subscriptions to generate push notifications
- use push notifications to run a push based sync engine
Part One - Project Planning, Model Objects, and Controllers
- follow a project planning framework to build a development plan
- follow a project planning framework to prioritize and manage project progress
- implement basic data model
- use staged data to prototype features
Follow the development plan included with the project to build out the basic view hierarchy, basic implementation of local model objects, model object controllers, and helper classes. Build staged data to lay a strong foundation for the rest of the app.
View Hierarchy
Implement the view hierarchy in Storyboards. The app will have a tab bar controller as the initial controller. The tab bar controller will have two tabs.
The first is a navigation controller that has a PostListTableViewController that will display the list of posts, and will also use a UISearchController to display search results. Both the PostListTableViewController and the SearchResultsTableViewController (from the UISearchController) will display a list of Post objects and segue to a Post detail view.
The second tab is a separate navigation controller that will hold a view controller to add new posts.
- Add a
UITableViewControllerTimeline scene, embed it in aUINavigationController, Make the navigation controller your first tab in the tab bar controller. (hint: control + drag from the tab bar controller to the navigation controller and select "view controllers" under the "Relationship Segue" section in the contextual menu) - Make the
UITableViewControllerfrom step 1 aPostListTableViewControllerCocoa Touch file subclass ofUITableViewControllerand assign it to the Timeline scene - Add a
UITableViewControllerPost Detail scene, add a segue to it from thePostListTableViewControllerscene - Add a
PostDetailTableViewControllersubclass ofUITableViewControllerand assign it to the Post Detail scene from step 3. - Add a
UITableViewControllerAdd Post scene, embed it into aUINavigationController. Make this navigation controller your second tab in the tab bar controller. - Add a
AddPostTableViewControllersubclass ofUITableViewControllerand assign it to the Add Post scene from step 5. - Add a
UITableViewcontrollerSearch Results scene. It does not need a segue to any other view controller.- note: You will implement this scene in Part 2 when setting up the
UISearchControlleron the Search scene
- note: You will implement this scene in Part 2 when setting up the
- Add a
SearchResultsTableViewControllersubclass ofUITableViewControllerand assign it to the Search Results scene.
Implement Model
Timeline will use a simple, non-persistent data model to locally represent data stored on CloudKit.
Start by creating model objects. You will want to save Post objects that hold the image data, and Comment objects that hold text. A Post should own an array of Comment objects.
Post
Create a Post model object that will hold image data and comments.
- Add a new
Postclass to your project. - Add a
photoDataproperty of typeData?, atimestampDateproperty, and acommentsproperty of type[Comment]. - Add a computed property,
photothat returns aUIImageinitialized using the data inphotoData. - Add an initializer that accepts photoData, timestamp, and comments array. Provide default values for the
timestampandcommentsarguments, so they can be ommitted if desired.
Comment
Create a Comment model object that will hold user-submitted text comments for a specific Post.
- Add a new
Commentclass to your project. - Add a
textproperty of typeString, atimestampDateproperty, and apostproperty of typePost. - Add an initializer that accepts text, timestamp, and a post. Provide a default values for the
timestampargument, so it can be ommitted if desired.
Model Object Controller
Add and implement the PostController class that will be used for CRUD operations.
- Add a new
PostControllerclass file. - Add a
sharedControllersingleton property. - Add a
postsproperty. - Add an
addComment(toPost: ...)function that takes atextparameter as aString, and aPostparameter. This should return a Comment object in a completion closure. - Add a
createPostWith(image: ...)function that takes an image parameter as aUIImageand a caption as aString. This should return a Post object in a completion closure. - Implement the
createPostWith(image: ...)function to initialize aPostwith the image and aCommentwith the caption text. Note: use theaddComment(toPost: ...)function you just created to call the appropriateCommentinitializer and adds the comment to the appropriate post.
Wire Up Views
Timeline Scene - Post List Table View Controller
Implement the Post List Table View Controller. You will use a similar cell to display posts in multiple scenes in your application. Create a custom PostTableViewCell that can be reused in different scenes.
- Implement the scene in Interface Builder by creating a custom cell with an image view that fills the cell.
- Create a
PostTableViewCellclass, add apostvariable, and implement anupdateViewsfunction to thePostTableViewCellto update the image view with thePost's photo. Call the function in the didSet of thepostvariable' - Choose a height that will be used for your image cells. To avoid worrying about resizing images or dynamic cell heights, you may want to use a consistent height for all of the image views in the app.
- Implement the
UITableViewDataSourcefunctions- note: The final app does not need to support any editing styles, but you may want to include support for editing while developing early stages of the app.
- Implement the
prepare(for segue: ...)function to check the segue identifier, capture the detail view controller, index path, selected post, and assign the selected post to the detail view controller.- note: You may need to quickly add a
postproperty to thePostDetailTableViewController.
- note: You may need to quickly add a
Post Detail Scene
Implement the Post Detail View Controller. This scene will be used for viewing post images and comments. Users will also have the option to add a comment, share the image, or follow the user that created the post.
Use the table view's header view to display the photo and a toolbar that allows the user to comment, share, or follow. Use the table view cells to display comments.
- Add a vertical
UIStackViewto the Header of the table view. Add aUIImageViewand a horizontalUIStackViewto the stack view. Add 'Comment', 'Share', and 'Follow Post'UIButtonss to the horizontal stack view. Set the horizontal hugging priority of the center button (Share) to 249 to distribute the buttons correctly. - Set up your constraints so that the image view is the height you chose previously for displaying images within your app.
- Update the cell to support comments that span multiple lines without truncating them. Set the
UITableViewCellto the subtitle style. Set the number of lines to zero. Implement dynamic heights by setting thetableView.rowHeightandtableView.estimatedRowHeightin theviewDidLoad. - Add an
updateViewsfunction that will update the scene with the details of the post. Implement the function by setting theimageView.imageand reloading the table view if needed. - Implement the
UITableViewDataSourcefunctions.- note: The final app does not need to support any editing styles, but you may want to include support for editing while developing early stages of the app.
- Add an IBAction for the 'Comment' button. Implement the IBAction by presenting a
UIAlertControllerwith a text field, a Cancel action, and an 'OK' action. Implement the 'OK' action to initialize a newCommentvia thePostControllerand reload the table view to display it.- note: Do not create a new
Commentif the user has not added text.
- note: Do not create a new
- Add an IBAction for the 'Share' and 'Follow' buttons. You will implement these two actions in future steps.
Add Post Scenes
Implement the Add Post Table View Controller. You will use a static table view to create a simple form for adding a new post. Use three sections for the form:
Section 1: Large button to select an image, and a UIImageView to display the selected image
Section 2: Caption text field
Section 3: Add Post button
Until you implement the UIImagePickerController, you will use a staged static image to add new posts.
- Assign the table view to use
