concept task in category ios

appears as: tasks, task, task, tasks
iOS Development with Swift

This is an excerpt from Manning's book iOS Development with Swift.

  • The activity viewer for information about the current state of currently executing tasks and status messages
  • Use the URLSession object and the URL (or URLRequest) object to create a task.
  • Set up a URL object using the thumbnailURL string.
    guard let url = URL(string: thumbnailURL) else {return}
    Because an image is a larger chunk of data that makes sense to receive as a file, you’re going to get the book cover using a download task from the URLSession. Because you’ll use the default configuration, this time let’s not instantiate a URLRequest, and instead instantiate the task passing the URL object directly.
  • 14.13. Cancelling a task

    It may have occurred to you that the user is currently able to exit the book edit form while a data or download task is in progress.

    iOS 7 in Action

    This is an excerpt from Manning's book iOS 7 in Action.

    Figure 3.8. Set the title of the navigation bar to Tasks to let your users know that this view will list all of their tasks.

    This will set the label’s text to the appropriate task that you need to display. The action to complete a task also hasn’t been hooked up yet. You’ll need to add the complete-Task: action to the following code to be able to remove the task from the tasks list:

    - (IBAction)completeTask:(id)sender
    {
        IAViewController *tasksListView = self.delegate;
        [tasksListView.tasks removeObject:self.task];
        [self.navigationController popViewControllerAnimated:YES];
    }

    First, you get a reference to the tasks list view, and then you remove the task from its tasks array. Finally, you call popViewControllerAnimatedYes: on the navigation controller to go back to the previous view.

    Go ahead and run the application, and try to add a task and complete it. Once a task has been marked as completed, it should be removed from the tasks list. Take a look at what we’ve created together in figure 3.19.

    3.1.2. Creating the interface for listing tasks

    Let’s add a table view that will be used to list the tasks that you want to display. With Main.storyboard selected and the interface editor open, look through the Object Library on the bottom right of the workspace window to find the table view, as shown in figure 3.3.

    Objective-C Fundamentals

    This is an excerpt from Manning's book Objective-C Fundamentals.

    Cocoa Touch consists of a number of frameworks (commonly called kits). A framework is a collection of classes that are grouped together by a common purpose or task. The two main frameworks you use in iPhone applications are Foundation Kit and UIKit. Foundation Kit is a collection of nongraphical system classes consisting of data structures, networking, file IO, date, time, and string-handling functions, and UIKit is a framework designed to help develop GUIs with rich animations.

    Relationships are the connections among entities—a class’s complex instance variables. A relationship points to another entity defined in your Xcode data model. When defining a relationship, you must also define the kind of association the object has to the class. It can be a one-to-one or a one-to-many relationship. An element with a one-to-many relationship is represented by a mutable set in the entry. With one-to-many relationships, much like with attribute definitions, you can also assign minimums and maximums for the set composing the relationship. A simple example is a task list that tracks multiple tasks assigned to multiple people. As a companion to your Rental Manager application, to help busy agents manage their schedules and tasks, you’ll build an iPhone application that can do the job, including checking off tasks when they’re completed. Let’s make these objects using Core Data’s tools.

    Figure 12.3. The person relationship for the Task entity. It isn’t optional (a task has to belong to a person), and it points to only one person, not to many.

    Using NSFetchedResultsController is already one of the best things you can do regarding performance of your iOS Core Data application. There are a few more things to keep in mind, though. If you know that you’ll always need access to a certain relationship of your entity, you should tell Core Data to fetch those child entities with the initial fetch request. Otherwise, Core Data would have to execute another fetch request for every entity. With 100 people, that would make 101 fetch requests (the initial one to fetch the people and one for each person to get the tasks). Using NSFetchResult’s setRelationshipKeyPathsForPrefetching: method avoids this overhead. In your example, to improve the performance when you fetch people, it would look like this:

    [request setRelationshipKeyPathsForPrefetching:[NSArray
         arrayWithObject:@"tasks"]];

    This code loads the tasks right away along with the people.

    12.4.8. Managing tasks

    Okay, you can list, add, and delete people in your application. The only thing missing is the ability to add tasks to a person. To do that, you create another UITableView-Controller subclass and call it TasksViewController. It’ll look basically the same as the PeopleViewController with only a few differences (you can copy and paste the code from PeopleViewController as a starting point): it’ll have a person instance variable of the type NSManagedObject and an init method called initWithPerson: that looks like the following listing.

    iOS 4 in Action: Developing iPhone and iPad Apps

    This is an excerpt from Manning's book iOS 4 in Action: Developing iPhone and iPad Apps.

    There are several ways to build a universal application running on both the iPhone and iPad. Let’s start with a handy checklist. (If you’ve already installed the Xcode and iOS SDK as demonstrated earlier in this chapter, you’ve finished half of the task.)

    In this chapter, we’ll first cover the multitasking basics, the application’s lifecycle on iOS 4, followed by the background state and best practices based on an app’s lifecycle transitions. Then we’ll talk about how to adopt fast app switching on the iPhone and iPad and how to update the application interface with the correct user data when the application gets restarted from the background state. Finally, we’ll use a demo app to explain how to finish a task in the background with an expiration handler. First, let’s explore some basics on multitasking.

    Listing 21.3 is an example of a task-completion API, showing how to finish a task in the background before the applications gets suspended. You can create a window-based project from the iOS template project in Xcode, because this part of API will only make changes to the app delegate file. In the app delegate header file, add in the task identifier: UIBackgroundTaskIdentifier bgTask. Define bgTask as a property of the app delegate, and synthesize it in the.m file.

    In this application, you want to finish a task, and after completion, send a local notification out to notify the user that the work is done. This example uses a simple method uploadPhoto to demonstrate the local notification setup in the background state. If you’re interested, you can look up Flickr’s photo-uploading API and add real photo uploading code into this method.

    Because the main purpose of this listing is to demonstrate the task-completion API, let’s take a closer look at how the job is done here. In the method applicationDidEnterBackground: you start the bgTask by calling the method beginBackgroundTaskWithExpirationHandler . The argument for the expiration handler is a block to end the task and release the bgTask. Then, with the help of Grand Central Dispatch (GCD), the task uploadPhoto gets called, and you end the task by calling the method endBackgroundTask: and release the task identifier by assigning the UIBackgroundTaskInvalid value to bgTask . We covered the GCD back in chapter 16.

    Save the changes, and build and run the application. Tap the Home button to let the application enter the background. When the application completes the task in the background, it will send out a local notification, as shown in figure 21.6.

    Figure 21.6. The application finishes the task in the background and sends out a local notification on the iPad and iPhone.

    Cool! You just managed to finish a task in the background. Always keep in mind that the permission and time limit are not guaranteed when you use the task-completion API. That’s why it’s a good practice to end the task gracefully instead of letting it get suspended when it doesn’t finish in time.