Presentation is loading. Please wait.

Presentation is loading. Please wait.

UMSI 363 Nancy A. Benovich Gilby

Similar presentations


Presentation on theme: "UMSI 363 Nancy A. Benovich Gilby"— Presentation transcript:

1 UMSI 363 Nancy A. Benovich Gilby
Busting Myths and Pursuing Information Innovations with Mobile Apps in SWIFT Week 5 Nancy A. Benovich Gilby Ehrenberg Director of Entrepreneurship Clinical Associate Professor  University of Michigan School of Information

2 Today The importance of “Team” The Agile model and roles
Your Project Starts Today: Meeting your teams, introducing yourself, articulating vision, goals Team communications covenant Form a Target User and Problem Hypothesis Start on MyBanks application: Learning objectives Snapshotting, Debuggin

3 Only exceptionally gifted, boastful folks make good innovators
MYTH #3 Only exceptionally gifted, boastful folks make good innovators

4 Only exceptionally gifted, boastful folks make good innovators
MYTH #4 Only exceptionally gifted, boastful folks make good innovators

5 "BUILD SOMETHING FOR SOMEBODY INSTEAD OF EVERYTHING FOR NOBODY" - Geoffrey Moore in Crossing the Chasm

6 You Will Be Forming TEAMS
You want the LARGEST DIVERSITY, innovation explodes with multiple perspectives, get them the easiest way by recruiting people to your idea area that ARE NOT THE SAME AS YOU RESPECT and INCLUDE everyone, all the time, every time. THE VERY FIRST THING INVESTORS LOOK FOR IS THE TEAM, THEN THE PEOPLE, THEN THEIR IDEA.

7 Why Bother with Agile? Importance of “Team”

8 Your Objectives in Team Formation
Shared values for: Project Outcome How you treat one another to form mutual respect and trust Prepare and welcome multiple views = encourage productive, non-personal, conflict Get as much out of the other person for the benefit of shared values in project outcome NON Objectives: To prove you are smarter, more competent, better developer, more industry aware…… You will succeed (or otherwise not do so well), on the project based on your ability to form a team

9 What Does it Generally Look Like without Agile?

10 Agile and Scrum

11 What Is It Like When You Start?

12 Agile, Lean, Design Thinking

13 Agile, Lean, Design Thinking

14

15 Team Formation

16 Introductions, Shared Team Values & Objectives
Hi, I am <name>, a <2nd yr> <masters> in <UMSI LIS> My area of passion is <shared economy> OR <undecided> NOTE: Speak loudly, firmly, shake hands firmly, look the person straight in the eye, don’t look away, SMILE, shoulders back, BREATH then HI…… YOU ARE CONFIDENT YOU BELONG HERE….. If you don’t feel it then PRETEND you do or ask yourself what would it look like if you were confident?????

17 Exercise 3 Value Hypothesis Business Model Canvas
WHO, SPECIFICALLY is the absolutely, no questions asked, FIRST person (NOT YOUR MOTHER) who will use your product or service? What is important about them? How do you find them? WRITE DOWN 3 bullet points the team agrees that describe this person

18 Exercise 3 Value Hypothesis Business Model Canvas
WHAT IS THEIR PROBLEM??, SPECIFICALLY what is a point of severe, gut wrenching pain (or what do you guess it is?) WRITE DOWN THE PAIN, FEEL IT

19 Exercise 3 Value Hypothesis Business Model Canvas
Formulate your hypothesis around their point of pain??, SPECIFICALLY what do you need to ask and verify to be sure you understand what you can fix in your passion area WRITE YOUR HYPOTHSIS …… Example: Type 1 diabetics most crucial issue is not having real time, accurate glucose data YOU HYPOTHOSIS IS NOT: Will Type 1 diabetics like my idea? NO LEADING THE USER

20 HOMEWORK HOMEWORK: Each person interviews 3 target users, records, writes 2-3 Post-IT notes on each interview Record – while recording ask permission, record on your phone, camtasia Follow the format on the next slide, it is called the KJ Method, takes about mins per interview:

21 HOMEWORK Teams, you must all help each other to find 3 target customers each. You may find after doing 1 or 2 that the attributes of your customer need to change or that you hypothesis is wrong and needs to change or both! HAVE FUN... THE AREA YOU CHOSE IS INTERESTING ... this is an opportunity for you to learn about your area of passion, it's not about if your idea is right or wrong, you have plenty of time to fix it. Instructions 1. Each team member, find three target users to interview. Record the interview (before recording ask permission. Record on your phone or use something like Camtasia). 2. DO NOT TELL THEM ABOUT ANY IDEAS/PRODUCTS, your job is to validate that problem/value hypothesis you formulated with your team by asking the questions below. 3. You will be using a structured Contextual Inquiry approach called the KJ Method, where you ask 4 Open-ended questions around your problem area: 1. Tell me about how you (do today without your intended solution? (Find out as much as you can about their worldview but DO NOT LEAD THEM) 2. What complaints, problems, weaknesses do you have? 3. What do you like? 4. What should we do (specifically, RIGHT NOW) to improve the weaknesses you mentioned prior? EXAMPLE: Area: 3D printing prosthetic hands Problem: People who need prosthetic hands cannot get them because they are too expensive Write the question as hypothesis: What are the most crucial problems in using 3D printed prosthetic hands? 1. Tell me about how you work with your hands? 4. What should we do (specifically, RIGHT NOW) to improve the weaknesses? 4. From each interview write down the 1 or 2 quotes on a post it note (IN THE CUSTOMER’S WORDS EXACTLY) that best answer your WHAT question. From the example: “What are the most crucial problems in using 3D printed prosthetic hands?”

22

23 Snapshotting in Xcode Handy way to keep a snapshot of your entire environment and code base in a file on your machine

24 Debugging in XCode Set breakpoints, Step into, Step over, use print/println or NSLog. Almost guarantee that if you crash ‘n burn into a stack track with an uncaught exception, you’ve not connected something correctly, and usually the stack trace doesn’t give you so much info, try to pinpoint, set a breakpoint and see if you get there.

25 Building Blocks for a FULL App
For an information app, it needs to have CRUDS Create, Read, Update, Delete and Search! You will bang your head, it will be frustrating but when you are done you will have a fully functioning app: Signup, Login, Password Recovery, Create/Update/Delete/Search (transactions), Search for Nearby Banks.

26 Debugging Examples

27

28 Assignment #8 Build the MyBanks App with Parse – Application Overview
Overview of the logic of the MyBank application: iOS Client – User Flow When the user comes in, they're not yet logged in. They have the ability to sign up and the ability to log in. This can also be skinned to your liking. Now when I log in, I can view my accounts balance

29 Assignment #8 Build the MyBanks App with Parse – Application Overview
Overview of the logic of the MyBank application: iOS Client – User Flow I can add some data, the balance updates. I go back. By clicking My Savings at the top. I can go to my profile and update both my user name and my password, as well as control my avatar from both the camera or the gallery

30 Assignment #8 Build the MyBanks App with Parse – Application Overview
Overview of the logic of the MyBank application: iOS Client – User Flow I can view all my transactions. I can go to my PF table controller and see the last two transactions that I've made.

31 Assignment #8 Build the MyBanks App with Parse – Application Overview
Overview of the logic of the MyBank application: iOS Client – User Flow I can view all banks within my location. So that's our functionality of My Bank

32 Assignment #8 Build the MyBanks App with Parse – Application Overview
Overview of the logic of the MyBank application: Back end This will be a financial application that's intention is to teach the CRUD methodologies for Parse. CRUD means Create data, the ability to Read data, to Update data, and then to Delete data. We'll also be experimenting with geo-points and files. On the back end we have 3 classes, User, transactions and locations

33 Assignment #8 Build the iOS MyBank App - Step 1
Get started with ParseSwiftStarterProject template If you have the parse-starter-project from the MyFirst app exercise, skip ahead. Otherwise, go to the Docs button at the top of parse.com, press the getstarted button or go to the think create for Data, Mobile, iOS, select Objective C (but we will write in Swift), New Project, download template, Open the ParseSwiftStarterProject.xcodeproject

34 Assignment #8 Build the iOS MyBank App - Step 2
Rename the project name to MyBank I do this A LOT when I am learning from existing code to get an app up and running from a starter project or tutorial! Click the project name ParseStarterProject in the upper left corner, rename it to MyBank. You’ll get a popup asking you to Rename Project content itmes, click Rename, enable automatic snapshots In Xcode, DO NOT Rename the code folder on the left to MyBank. QUIT XCODE. In Finder rename the overall project folder ParseSwiftStarterProject to MyBank, Unfortunately there is an issue with Xcode and Swift (Stack Overflow has an answer for the Tests folder but no the main code folder. If you do figure it out, 3 extra credit points if you post to Canvas 

35 Assignment #8 Build the iOS MyBank App - Step 3
Check that your app compiles and runs If not, you might have not changed things in the right order, copy template file. RUN FIRST, then change names. You should get the notifications and a blank screen

36 Add the App Story Board

37 StoryBoard Ultimately your app will be a full CRUD with login template that should provide scaffolding for any app you might like to build We’ll put together the UI elements, then proceed to adding the necessary code for all the CRUD functionality

38 Assignment #8 Build the iOS MyBank App - Step 4
Layout the Top level view, embed the view in a Navigation Controller In Xcode, select the ViewController. and in the Xcode menu go to Editor > Embed In > Navigation Controller. This adds a Navigation Controller to the storyboard with an initial scene. Select the Navigation controller, on the right most xcode pain, select file inspector and uncheck Use Size Classes to keep layout just for an iphone

39 Assignment #8 Build the iOS MyBank App - Step 5
Layout the Main ViewController In Xcode, layout a Welcome lablel , blank label next to Welcome for the name and 5 buttons as below. Give the buttons a background color so they are easy to see. You can create the first button then copy – paste and edit the remaining

40 Assignment #8 Build the iOS MyBank App - Step 6
Layout the Account ViewController, make the Main View Controller push segue when the View Account button is pressed. Repeat with the Profile View Controller . In Xcode, copy – paste the main view controller, change the Welcome Label to Balance, add a Reason and Amount lablel, add 2 fields, change a button to Make Transaction, delete the rest Click control drag from the View Account button on the Main View Controller release on the Account View Controller, select push segue. Repeat for Profile View Controller, connect it to the View Profile button with push segue

41 Assignment #8 Build the iOS MyBank App - Step 7
Layout the remaining views Transaction Table ViewController, Search PF Query Controller, and the All Banks View Controller, Build & Test In Xcode, pull TableViewController onto the main story board. Select it, go to Editor on the Xcode menu bar, >Embed In > Navigation controller. Delete the new Navigation Controller (this give you all the spacing etc you need for the table view controllers to work with the Navigation Controller Click on the View Transactions button in the Main View Controller, click control drag to the TableView Controller, add a push segue Copy – paste twice the Transactions view controller so you have 2 additional table view controllers. Click control drag create to create a push segue from the PFTableController button on the Main View Controller and to the other, click control drag from the View All Banks button. You should now have The Navigation Controller, Main View Controller, Account and Profile View Controllers and Transactions, PFTable and View All Banks Table View Controllers Build, run test, all the buttons should go to their corresponding view and have a Back button that goes back to the main view.

42 Assignment #8 Build the iOS MyBank App - Step 7.A
Add the Search Bar to the SearchPF Query Controller In Main.storyboard, drag a Search Bar and Search Display Controller and place it just under Prototype Cells text in the the SearchPFQueryController as below. Interface builder wires it up for you.

43 Assignment #8 Build the iOS MyBank App - Step 7.B
Add the Search Bar to the SearchPF Query Controller We need to remove one of the wires however for search to work correctly. With the Document Outline open, Click on the Search Display Controller on the left. Open the connections inspector in the right panel and delete the searchBar outlet so it lis the same as below.

44 Create New Classes for the New Views in the Story Board

45 Assignment #8 Build the iOS MyBank App - Step 8
We now have a full storyboard with all the views but the views have no code to control what they display and how they react. Add Classes for all the new views In Xcode, Go to the Xcode menu File, new > Cocoa Touch Class> Give the class the name AccountViewController, subclass of UIViewController, iPhone, language Swift File, put in the the ParseStarterProject, Create. Repeat to create the ProfileController as a subclass of UIViewController Repeat for TransactionViewController EXCEPT, make it be a subclass of UITableViewController. Repeat with the same superclass UITableViewController to create SearchPFQueryController and AllBanksController

46 Connect the new Class code files to the Corresponding Views in the Storyboard

47 Assignment #8 Build the iOS MyBank App - Step 9
We now have a full storyboard with all the views, Classes but we need to connect the classes to their corresponding Views In Xcode, in the storyboard, select the Account view controller, Click the first responder button on the top left of the view, select the identity inspector on the right panel in Xcode, in the Class pull down select the AccountViewController Repeat for all the remaining views to connect ProfileController, TransactionViewController SearchPFQueryController and AllBanksController

48 Connect the the Outlets and Actions on each of the views

49 Assignment #8 Build the iOS MyBank App - Step 10
We now have a full storyboard with all the views, Classes connected now we need to connect all the outlects and actions (or create actions) In Xcode, in the storyboard, select the main ViewController. Select the blank text label next to Welcome, we are going to make it an outlet for the user’s name. Click the assistant editor on the top right xcode, it will bring up the code for the ViewController, control click drag to the viewcontroller code, create and outlet called Welcome. Repeat with the AccountsViewController to create BalanceLabel, reasonText and transAmount outlets. Create an action (make sure it is NOT an outlet) called makeTransaction from the Make Transaction button. Leave the code in the action blank for now Repeat with the ProfileController to create unameText, pwordText, chooseButton and pic outlets. Create a blank code actions called UpdateInfo from the Update button, TakePic from the Take Picture Button, choosePic from the Choose From Gallery Button

50 Assignment #8 Build the iOS MyBank App - Step 11
We now have a full storyboard with all the views, Classes connected now we need to connect all the outlects and actions (or create actions) In Xcode, in the storyboard, select the main ViewController. Select the blank text label next to Welcome, we are going to make it an outlet for the user’s name. Click the assistant editor on the top right xcode, it will bring up the code for the ViewController, control click drag to the viewcontroller code, create and outlet called Welcome. Repeat with the AccountsViewController to create BalanceLabel, reasonText and transAmount outlets. Create an action (make sure it is NOT an outlet) called makeTransaction from the Make Transaction button. Leave the code in the action blank for now Repeat with the ProfileController to create unameText, pwordText, chooseButton and pic outlets. Create a blank code actions called UpdateInfo from the Update button, TakePic from the Take Picture Button, choosePic from the Choose From Gallery Button Build, run, test everyview…..You will have a warning: Main.storyboard: Prototype table cells must have reuse identifiers

51 Connect the App to the Parse Backend

52 Assignment #8 Build the iOS MyBank App - Step 12
Note how to Create a Bridge between Swift and Objective C so we can use Objective C methods in our code. Add the imports we need The template already has a Bridge file for you but if it didn’t you would do the following: Right Click MyBank folder in Xcode, select New File from the menu, Objective-C file, name it BridgingHeader, leave it as an empty file, click Finish. You’ll be asked if you would like to configure an Objective-C bridging header, say Yes . You’ll see and .m (implementation) and .h (header file were created, you can delete the .m file, we just need the .h to import the Parse framework We do need to update the bridging file to add :Add the following to ParseStarterProject-Bridging-Header.h. (It an be found in ParseStarterProject>SupportingFiles . The first line imports the Parse framework with a traditional Objective-C import statement. The second import will allow me to subclass certain Objective-C methods.

53 Assignment #8 Build the iOS MyBank App - Step 12
Connect your Parse backend Keys in the AppDelegate Delete the code to simplify this class per below, add the code for the method didFinishLaunchingWithOptions Replace "your_application_id” "your_client_key” in xcode with the corresponding keys in Parse.com for you MyBank application (Settings on top, Keys on the left) If you read through the code you’ll see the template sets up the ACL, local data store etc for you, just leave it. Keep in mind, these keys are not what makes this application secure. Controlling the access control list will make it secure.

54 Assignment #8 Build the iOS MyBank App Step - 13
Add external Cocoa Touch libraries to your project To Libraries for the Parse Framework, go to Build Phases on the top of Xcode, click Link Binary with Libraries, click the + and add: CF Network, CoreGraphics, CoreLocation, libz.dylib,, QuartzCore. (NOTE: you can command click to select multiple frameworks!!) Select copy items if needed If you don't have any of these frameworks, you can update your Xcode or go to the Apple site to download 'em. We'll also add Security, Storekit,, Accounts, and lastly, a Social.framework.

55 Signup And Login

56 Assignment #8 Build the iOS MyBank App – Security and PFUser Object

57 Assignment #8 Build the iOS MyBank App – Security and PFUser Object

58 Assignment #8 Build the iOS MyBank App – Security and PFUser Object
When we get ready to ship your app, you can “Lock Down” Parse to make it more secure

59 Assignment #8 Build the iOS MyBank App – Security and PFUser Object

60 Assignment #8 Build the iOS MyBank App – Security and PFUser Object

61 Assignment #8 Build the iOS MyBank App Step - 14
We will be adding our Login and Signup functionality for our banking application. First, we'll need to add the Access Control List permissions for the user in our AppDelegate. We can control our user Access Control List for Parse. Since this a financial application, we should only allow the user to see the financial data. So we’ll change the code for the variable called defaultACL . This variable has different methods for allowing read and write access. Set PublicReadAccess to be false as below. You’ll notice we call the method PFACL.setdefaultACL to be that variable defaultACL with AccessForCurrentUser, true. So, once that user logs in, he and he alone will have access to the data.

62 Assignment #8 Build the iOS MyBank App Step - 15
Now we'll need to integrate both the PFLoginViewControllerDelegate and SignupViewControllerDelegates. In Xcode, we need to add our delegates to ViewController. Parse provides both a PFLogInViewController and a PFSignUpViewControllerDelegate. Next thing we need to do is set a title on the ViewController, then test to see if our user is logged in. We can test this through the PFUser object. If that user is nil we'll know they need to log in. Or sign up. If you want to look at all the possibilities (including login with Facebook or Twitter, look here

63 Assignment #8 Build the iOS MyBank App Step - 16
Now we'll need to integrate both the PFLoginViewControllerDelegate and SignupViewControllerDelegates into ViewController Next thing we need to do is test to see if our user is logged in. We can test this through the PFUser object. If that user is nil we'll know they need to log in. Or sign up. So what we'll do is we'll create variables that equal the controllers that Parse provides for us. Now we can control the fields the User sees when he arrives at the screen. Parse has an object called PFLogInFields that allows us to pipe delineate the fields that we want to choose. It's all very simple with code entering. So only a SignUpButton. We'll need a LogInButton of course. We'll need a PasswordForgotten field. And you can even use Social Media. There's even a Facebook button. In this case we're doing a financial app that we do not want to be public so we'll omit the Social Media.

64 Assignment #8 Build the iOS MyBank App Step - 17
Now we'll need to integrate both the PFLoginViewControllerDelegate and SignupViewControllerDelegates into ViewController Next thing we need to do is test to see if our user is logged in. We can test this through the PFUser object. If that user is nil we'll know they need to log in. Or sign up. We’ll override the viewDidAppear method. So what we'll do is we'll create variables that equal the controllers that Parse provides for us. Now we can control the fields the User sees when he arrives at the screen. Parse has an object called PFLogInFields that allows us to pipe delineate the fields that we want to choose. It's all very simple with code entering. So only a SignUpButton. We'll need a LogInButton of course. We'll need a PasswordForgotten field. And you can even use Social Media. There's even a Facebook button. In this case we're doing a financial app that we do not want to be public so we'll omit the Social Media.

65 Assignment #8 Build the iOS MyBank App Step - 18
We’ll setup the initial login and signup screens if the PFUser.currentuser == nil and test Next thing we need to do is delegate to ourselves. So I'll add a delegate to the Login that equals self, or this controller. Then I'll go to the Signup and do the same thing. Now the next thing we can do is get the login object and get it's signup controller, and make it equal to the signup variable. So now the login object has that signup controller as part of it's properties. Now we simply need to present the controllers. And in this case we're going present login to be true, and the completion to be nil. The true needs to be small case. Now if the user is already logged in we're going to need to grab their username and welcome them. And give them some sort of notification that they're already logged in. Parse security means that the user will stay logged in until he either resets his application or deletes the app, orr logs out. So I have a username and that'll be part of the PFUser object. The currentUser property has it's own property of username. In the screen that we wired while building the UI, there's a Welcome label, Welcome text and that can be equal to username. So let's run this. And here you see the Sign up screen. Make sure to say OK to allow MyBank to send Notifications See the code on the next page

66

67 Assignment #8 Build the iOS MyBank App Step - 19
we'll add the delegate methods that'll allow our user to have functionality when they actually sign up and log in, starting with the method signUpViewController in the ViewController file When a user signs up , we'll need to add an object to the database, and when they log in, we'll need to remove the controllers and send them to the application. Parse provides a lot of delegate methods for this functionality. One of the most important is what occurs when the user signs up. Here you see the delegate methods they offer. They have didFailToSignUpWithError, didSignUpUser, which we'll use, as well as others. In this case, what we'll need to do is take the user object and actually create the user out of it. So, I'm going to create a variable that equals the PFObject for the className for which we'll need to enter a record. This is CamelCased and if you recall when we created our database, we had a field called "transactions". That holds all the transactions that the user makes with both withdrawals and deposits. So, what we're going to need to do is create the object and add the user object to that. So, we can access the accountholder column which is the property of that object. And we can make that equal to the PFUser Object. That means that our account belongs to that user and that user only. Lastly, we can create a saveInBackgroundWithBlock method so that we can test whether we're successful or we fail.. Success will be a Bool and the error message will be a property of the NSError object. And that'll be explicitly wrapped. We'll need a Void in and now we can test of success. NOTE XCODE DOES NOT PUT IN A { } AROUND BLOCKS, YOU MUST GO BACK AND PUT THEM IN!. If success is not equal to nil, we'll know that we've been successful. And we'll simply log it for now. But, when we go live with this application, we might give a UI alert message to let the user know they were successful, as well as dismissing the controller. So, otherwise, there's no success. We'll output our error. And lastly, what we'll need to do is add an opening brace and a closing brace and then dismiss the controllers, and it'll be true and the completion will be nil. See code for the signUpViewController method on the next page

68 NOTE user.saveInBackgroundWithBlock{( ……) ……………}, you must put the {} around the code block

69 Assignment #8 Build the iOS MyBank App Step - 20
Handle the case where the user clicks the signup button by mistake and needs to cancel, and the case when the user logs in, in ViewController file We’ll add a delegate method for user tries to sign up and cancels, signUpViewControllerDidCancelSignUp, and the code here simply dismisses the controller. This can happen if the user attempts to log in and clicks the sign up button by mistake. So, we'll allow them to dismiss their controller and go back to the log in screen. The last things we can do with the delegate method is what happens when the user successfully logs in. In this case, we'll use the didLogInUser object. And we'll do the same thing. We'll dismiss the ViewController because the user logged in. So, now we can go ahead and test, by sighing up (add a user name, password and ) then you should be logged in and the welcome text updated with your user name

70 Assignment #8 Build the iOS MyBank App Step - 21
Make a transaction, put it in the Parse database, in AccountViewController file, makeTransaction We'll be taking the text values from the Reason and Amount fields and taking them and putting them into the Parse database in the Transactions class. I'm going to AccountViewerController swift. All the outlets and actions were wired when we put together the UI so that we now can focus on our code. In the makeTransaction method, the first thing I need to do is extract the value of the Amount of the transaction. In this case, I'm going to make it equal to the TransAmount text property. But I'm going to cast it as an NSString so I can take advantage of it's double value property. I'm also going to grab the reasonText from the reason field. Now that I have these I can worry about my object. The first thing I need to do is make a variable equal to the object that I want to alter. So I'm creating a var called transactions, which will be equal to the PFObject for that className. If you recall, transactions is the class we built in the backend in Parse that had not only account holder but reason and transaction. That takes care of our financial data. Now I can set my objects, fransaction, which is the amount of the transaction. We're setting that specific column to be equal to deposit. If you recall we created that as a number in our database. Now we'll go to the next one. This'll be called reason. And that can be equal to the reason variable. We'll also need to account for our which account holder this data should go into. So we'll access the accountholder column which was the pointer that pointed at the user object. This means we have to make it equal to the current user if those transactions are to be in that user's account. Our next step is to save this InBackgroundWithBlock. I'll add an opening brace and I'll create my success block. So on success, which will be a Bool object, yes or no, true or false. Do the same error handling we had before, with a comma separation.. We'll add our Void in and test our success. If success not equal to nil, we know that we had some success and we can log that just for testing. Or give a UI alert message that the transaction was successfully logged. Else if there is an error, the error variable will hold that value. So that's our transaction and we need to make sure that we clean up all our errors. And our next step, will be to call the database and learn how to use that PFQuery object in order to display the values. See the code for the AccountViewController, makeTransaction method on the next page

71

72 Assignment #8 Build the iOS MyBank App Step - 22
Query the Parse database, display the value, in the AccountViewController file, viewDidLoad method. Then in the makeTransaction method, we’ll need to update the balance for everytime our user has made a transaction In the viewDidLoad method, we will declar a user object. Our goal here is to call the Parse database and find all transactions that our user has made, regardless of whether they're withdrawals or its. We're going to create a query using the PFQuery object that Parse provides for us to find these values. We'll tabulate them and append the sum to a BalanceLabel in our controller. Start by defining a variable, trans in AccountViewController and setting it’s initial value to 0.0 I'm creating a variable called query. It equals the PFQuery object. In this case, we're going to call the class name of transactions. That's the object that holds all of our data for transactions, which includes the amount of the transaction, the reason, and the user, which is a borrowed key called "accountholder." In order to find only transactions our user has made, we use the whereKey method. In this case, the field or object that holds our key is called "accountholder." We'll find that value where it's equal to our previously-declared user object. Now that our query is done, we'll need to extract the data from the query. We can do that with the findObjectsInBackgroundWithBlock method. XCode doesn't provide an opening brace for us, so I'll have to do that. Now I can create my "success" and "error" blocks. On success, I'll want to create a variable called "objects," which, for now, will be cast as Swift's AnyObject. In our error block will be an instance of the NSError object. Add the void in and then we’ll test to see if the error is nil. If it is, we can go in and extract our data. I'm going to create a variable called "accountObjects." If we can assign the variable of accountObjects to be equal to the objects variable from our success block, optionally cast as a PFObject, then we can create a loop that extracts our data and continually concatenates to a trans variable. I'll do this with a for and loop. I'll create a variable called "transact." For each transact inside our previously-declared accountObjects, we can proceed to access the self.trans variable, use a += to continually concatenate, and find our value of each transaction through the transact object in the transaction field. We'll need to cast this as a Double. After this is complete, we can create a variable that will hold our formatted text, which we can assign to our balance label. I'll use the NSString, because it has a great formatting method. In this case, I'll need to format to the second decimal place, as we're talking about currency. The value in question will be self.trans. We'll access the BalanceLabel and its text property and make it equal to the string. We'll need to close that block of code with the }. Inside our makeTransaction method, we need to update the balanceLabel for every time our user has made a transaction. To do this, we'll need to access the value inside our label field. We'll create a variable called "currentBalance" that equals NSString of a string object of that BalanceLabel. However, before we can prove our math in this, we need to cast it as a Double. I can do that with the old doubleValue. Now I can make a variable called "total" which equals that currentBalance plus the amount the user has just entered. I need to reappend that value to our BalanceLabel so the user sees the update. Again, I need to format that value. Once again, we'll use NSString to do that. Lastly, we'll need to clear out the value from our text fields as now the fields have been processed. Our transAmount text property will be equal to an empty string, and so will our reasonText . Now we build, run our test. I'll click on the View Account Button. I have a 0.0 for the balance. But now let's add a paycheck. 500, press the Make Transaction button. Now let's make a withdrawal, -20 for Starbucks And you see our balance updates. That's how we can make a query to the Parse database using the PFQuery object. See next slidefor screens, the following for code

73

74

75 Assignment #8 Build the iOS MyBank App Step - 23
Copy example methods for picking a pic from the gallery and taking a pic in the ProfileView, In the ProfileController, add the import statements for CoreData and MobileCoreServices at the top, Add delegate UINavigationControllerDelegate,UIImagePickerControllerDelegate, PFLogInViewControllerDelegate Add the imagePicker and popImage to the ProfileController class with the initial valuse as below. there are 2 methods directly copied from googled examples for taking a picture with the camera (doesn’t work in the simulator) and to choose a picture from the image gallery. We’ll populate the TakePic and choosePic action methods that we created as actions when we were laying out the UI and add the code for the imagePickerController, imagePickerControllerDidCancel and override touchesBegan. See code below. Build, run test the choose picture by clicking the Profile View button on the main ViewController

76 Assignment #8 Build the iOS MyBank App Step - 24
Write the logic for the ProfileView, showing how to update an object in Parse. In the Profile View you see before you there's a username, a password, an update button, as well as an avatar image view. This will be an opportunity to teach you about the PFFile object. Keep in mind passwords are always invisible in Parse. So initially we'll go to the ViewDidLoad method. Our goal here is to populate the username with text on load and to test to see if there is an image in the database and if there is, we'll populate that image view with that image. So now you'll learn how to get data from a file object. So the first thing we'll do is make a user variable that equals the PFUser Object. Now we'll make a variable called username which will equal the username property of that object. Now we can populate the username text with that. The password's invisible so we won't populate with that. What we'll do is if the user enters a password, if it happens to not be nil then we'll update the password. Now it's time to grab the image from the database if it exists. So I'm going to use a condition and I'm going to let a variable called userImageFile equal an instance of the user avatar object. Avatar is a column we created in our database of an optionally unwrap it because it might not exist, and then we can write into the conditional if there is an image. So I'll grab that value, we'll make it file, and we'll use the method getDataInBackgroundWithBlock. You can also use the progress block, if you think it's a large image, but we really should keep minimal data in the database. So the value of the data will be imageData and that will be a property of the NSData Object. The error will be the traditional NSError. Now the auto populating NS code will not populate with an opening brace so be cautious of that because it will trigger an error. Now inside here if we're actually able to get data, we can grab that data and populate the image with it. So I'm going to test if error is equal to nil, and if it is we'll have some data. So at that point I can create a variable, and make it equal to an instance of the UI Object that has the data of the data from the database. Lastly, I can assign the pic on our screen to have that data. So if there's an avatar, at this point, it would populate that element. You also have to void as we're not returning anything. We'll build and clean to see if that makes the error go away, and it does. So our next step is to go into our action called UpdateInfo. This is how we update an object. We're going to use the PFUser Object again, currentUser and we'll attack the username first. We'll make that equal to what's in the text field. Pretty simple and straight forward. As far as the password, we'll only want to update if there is value in the password field. So if pwordText.text is not equal to nil then we can update that. Pretty easy. But what if our user hasn't uploaded an image for their avatar? Well, we can test popImage for nil and if it is nil, we can create a variable called silhouette that will equal an instance of the UIImage Object. In this case, an image named silhouette.jpg (google, find one you like, download, add to the Supporting Files Folder as silhouette.jpg with the Xcoe, Files> Add Files to “My Bank” menu). Next, we can place that image on our pic Object. Now we can play and run a test. I'll click on my view profile. I'll update my username and you see the silhouette image here. Let's choose one of the default pics from our gallery. Click Choose and now that will be our avatar, and that's how we can control our profile in Parse.

77 ** Note image from gallery is not saved

78

79 Assignment #8 Build the iOS MyBank App Step - 25
Example TableView methods for TransactionsViewController with data from Parse, create prototype cell in storyboard For efficiency in all TableViews, we want to create a prototype cell in the storyboard, call it cell, for use with the dequeueReusableCellWithIdentifier method as below, add 1 to prototype cell in TableView, indentifier cell in the TableView Cell

80 Assignment #8 Build the iOS MyBank App Step - 26
Example TableView methods for TransactionsViewController with data from Parse In Transaction View Controller is where the data from the user's transactions will populate. We'll go into our Transaction View Controller . We'll first focus on a method called loadData. This will teach you how Parse handles cache values. I add a variable called transactionsData which is an NSMutableArray. The first thing I'm going to do in this method is to removeAllObjects. This method will be called on refresh when the user pulls down the table, or even on load. So the first thing we'll do, is remove all those objects. The second thing we'll do is create a user object. So this will be called currentUser, and it will be equal to the PFUser object. If that currentUser... is not equal to nil, we can access the data. The next thing we'll do is to create a variable called findTransactionData. And this can be equal to an instance of the PFQuery object with a className... from our database that's called transactions. Now findTransactionData will have a lot of properties regarding cache and cachePolicy. In this case our cachePolicy... Can be equal to ElseNetwork. The kPFCachePolicyNetworkElseCache will allow us to function if there is no network capability. Now what we can do is test to see if there are results in our current cache. So the hasCachedResult property will tell us about that. We can also clear the cache... For that specific result. Additionally, we can clear the entire cache for the PFQuery object, and clearAllCachedResults. We can also set a limit for dates, called maxCacheAge. And that's equal to seconds. So I'll give it a full day of seconds. Now we can do it make a query for all our transactions. So what I'm going to do is findTransactionData, the PFQuery object, and we're going to ask it for the Key of accountholder, which is the user object. So we'll do equalTo, our user object which is currentUser. We'll also want these to be in ascending order. We can do orderByAscending or Descending. We'll do Descending, as we want the latest to appear at the top. So the object we'll use here is that createdAt column that gets created by Parse automatically. Now what we can do is find our data. So we'll use findObjectsInBackgroundWithBlock. Again, we have to open up a curly brace as it does not auto populate. And what we can do in here is create an objects value that can be an instance of AnyObject. And the error will be our traditional NSError. We'll do our Void in, and now we can go in and extract that data. So if error is equal to nil, we'll have some success. And for this time, we're gonna have to loop around our object's variable. So I'll do a for in loop for object in objects. Let's continually add those objects. So I'm gonna use the addObject property of the PFQuery object, and the object we can add is simply the individual object. So lastly, I can do a self.tableView.reloadData() to reload our table with the new data. I can even control the refresh. I'm gonna optionally wrap that to endRefreshing(). See next slide for code Now add the code for the viewDidAppear and viewDidLoad methods.

81

82 Assignment #8 Build the iOS MyBank App Step - 27
Populate the TransactionsViewController TableView with data from Parse, using example code The next step is to populate our table cells. Since you have experience with iOS Table Views, you'll be familiar with the required methods numberOfSectionsInTableView, and numberOfRowsInSection, which returns of the count of the objects transactionsData.count. We see a template that we’ll fill in with Parse code for how to delete a row and thus a transaction from Parse. More importantly, we see the method, cellForRowAtIndexPath, for how we populate our table cells with data from our Parse object. We're assigning a variable account to be equal to a PFObject of the specific object in that table cell. That's where the indexPath.row is. Further we're creating a variable called transdata that's cast as AnyObject that equals the row in the database account["transaction"]. That's where our user puts his withdrawal or deposit values. Finally, we're using NSDate formatting from Objective-C to format our date. And lastly, we return the cell.

83 Assignment #8 Build the iOS MyBank App Step - 28
Populate the TransactionsViewController TableView with data from Parse, using example code Now we’ll add the method, cellForRowAtIndexPath, which populates our table cells with data from our Parse object. We're assigning a variable account to be equal to a PFObject of the specific object in that table cell. That's where the indexPath.row is. Further we're creating a variable called transdata that's cast as AnyObject that equals the row in the database account["transaction"]. That's where our user puts his withdrawal or deposit values. Finally, we're using NSDate formatting from Objective-C to format our date. And lastly, we return the cell.

84 Assignment #8 Build the iOS MyBank App Step - 28
Populate the TransactionsViewController TableView with data from Parse, using example code Now let's finish our Delete functionality, and show you the final letter of the acronym CRUD. We've done Create, Read, Update, and now it's time to Delete. So what we can do is actually grab the value of that object, the same way we did to populate a table cell. We'll use the objectAtIndex, and we'll use indexPath.row. That'll be the specific object we intend to delete. The method we're gonna use is deleteInBackgroundWithTarget. Our target will be nil, and be cautious for case sensitivity as Xcode will pre-populate that with a separate method, our selector will also be nil. I'm using the deleteInBackgroundWithTarget instead of deleteInBackgroundWithBlock, because it'll give you the opportunity to code a method that will alert your users when the delete has occurred. So we'll keep that as nil as well. The next step is to remove the object itself. So I'll take transactionData which you can as a PFObject, and what we're going to do is removeObjectAtIndex. And this will also be indexPath.row. And that will remove the data from Parse. The last line, deleteRowsAtIndexPaths will delete the row from the user's visibility.. Now let's run a test, in the simulator View Transactions, and you'll see any deposits and with drawls you’ve made. Try deleting a transaction, make sure the amount updates correctly in View Account. See the screen shot on the next slide.

85

86 Assignment #8 Build the iOS MyBank App Step - 29
Adding logout functionality in ViewController We're in the ViewController, Remember, either the user is logged in already or they need to sign then login. Right after the Welcome.text = username, we’re going to create a dynamic button for our navigation bar. The dynamic button is an instance of the UIBarButtonItem class and we can add attributes for it. Our title can be simply 'Log Out'. Our style can be plain. Our target will be self for this class and our action will be the method name. At this point we have our Log Out button but now we need to add it to the Bar. So I'm going to call on self.navigationitem and it's right in our ButtonItem property And make that equal to our Log Button. Now, all I need to do is code the Log Out function. The sender will be the BarButtonItem. So how does Parse log somebody out. Well it's pretty easy. We take the PFUser object and apply it's LogOut method. We can also attack any variable that might still hold a value. I make a variable called currentUser and make it equal to PFUser. Now that value will become nil. But that's not all that needs to happen. When a user logs out, he needs to be redirected to the login screen. So now we'll create a variable called login that equals the PFLogInViewController We can dismiss our own controller since we're logged out and we can present the new Login Controller. Which is login, we can animate that as true. Then on completion have a nil Run a test, Push our Log Out button and now we're logged out. See the code and screenshots on the next slide

87

88 Assignment #8 Build the iOS MyBank App Step - 30
Explore the functionality of PFQueryTable for search and pagination When you make it this far, you are ready for some advance functionality provided by Parse.frameworks in PFQueryTableViewController. It inherits fromthe UITableView and offers some extra functionality, like pagination, ability to refresh with one delegate method. Open the SearchPFQuearyController class For efficiency in all TableViews, we want to create a prototype cell in the storyboard, call it HeaderCell, for use with the dequeueReusableCellWithIdentifier method. Add 1 to prototype cell in TableView, indentifier cell in the TableView Cell In the SearchPFQueryController, note that it has the delegate, UISearchBarDelegate. Majsure you import from Foundation and UIKit. We are going to add some functionality to the init method to give you an idea what this offers. The benefit of this Controller, by the way, for the application will be search functionality. That's why we've included the UISearchBarDelegate. So the methods that it provides are also very, very helpful. So the first thing we do is look at some of the methods offered by the PFQueryTableViewController. One is pullToRefreshEnabled. We can make that equal to true. One thing we can do is to call in a class name, we will do self.parseClassName and make it equal to what we're searching through, which is the transactions. There's some other useful things. I have minimal data so I'm will register this and leave it in the code. paginationEnabled, Make that false. But that's a very handy method that'll paginate for you. To make that work all you have to do is declare an objectsPerPage. So, let's say you wanted minimal per page, it would create pagination for you. So as we scroll down, we have traditional tableView methods, viewDidLoad, heightForHeaderInSection, viewForHeaderInSections, code on the next slide

89

90 Assignment #8 Build the iOS MyBank App Step - 31
SearchPFQueryController method queryForTable method When you make it this far, you are ready for some advance functionality provided by Parse.frameworks in PFQueryTableViewController. It inherits fromthe UITableView and offers some extra functionality, like pagination, ability to refresh with one delegate method. Open the SearchPFQuearyController class Notice the variable query that equals the PFQueryObject. Here we need to do two things. We need to determine if the user has entered search text, and if they have, write a query with that search. Or simply just list all the transactions. So let's first test to see if the user has entered any search text. Because we have the UISearchDelegate, we actually have a property called searchText. That's part of that search bar. And that has a property called isEmpty. So if the searchText isEmpty, we'll know we need to create our own query and call out every transaction. So I'm going to do a query.whereKey, and in this case, the accountholder needs to be equalTo the user object. And in this case, I'll just call on the PFUser object again and we'll get currentUser directly inside these braces. And now we need to append how we want that ordered. So I'll use query again, so we'll do orderByDescending. And the value on that will be createdAt, that pre-populated column that Parse provides for us. So that's if the user hasn't searched any text. Well, let's take care of if they have. In our else statement what we'll need to do is add the same query based on the user object. We'll need to also orderByDescending. And lastly, we'll need to append to this query where the key of reason, which is the field that holds the reason for the transaction, where that's equal to the searchText. So I'll type in query.whereKey and reason will be our object name. That'll be containsString and the value of the user search, which is searchText. So what we have here is a query based on the fact that our user has entered some searchText. After the . queryForTable, you’ll add the required cellForRowAtIndexPath as in any TableView. In this method, the cell identifier is actually PFTableViewCell. It inherits from that class. On line 79, we're going to create a variable called reason that'll be equal to the object reason. We'll have our transaction and we'll have a formatted string

91

92 Assignment #8 Build the iOS MyBank App Step - 32
SearchPFQueryController, UISearchBarDelegate methods Next we need to add searchBar delegates methods, These are all pre-populated delegate methods provided by that delegate object. We can show the CancelButton. On BeginEditing we can make the CancelButton be true. On EndEditing it'll be false. These are all part of the IOS docs. Now run and test. Look for a transaction you know you have (I have paycheck). Parse does not honor case insensitive searches. It's up to the developer to come up with a method to match the query to the data in the database. It will offer regular expressions, however. So that's the PFQuery TableViewController.

93 Use Geolocation to Find the Nearest Banks

94 Assignment #8 Build the iOS MyBank App Step - 33
Use Geolocation to find nearest banks In our AllBanksController, in the Main.storyboard, makesure the table view prototype cell is one and call the prototype cell cell , let's add the loadData function. In here you'll see if the User is not equal to nil or if they're logged in. We'll create a query that's an instance of the PFQuery object. What we need to do is show how to initiate PFGeoPoint, which is a class that Parse offers. So what we'll do is we'll call on PFGeoPoint and its property geoPointForCurrentLocationInBackground. Inside we're going to create a variable called point and that will be equal to where the user is at the current time, instance of the geoPoint object. And we'll also create an error block, that's wrapped and a Void in and a closing brace. Our next step will be to create a Query based on where the user's located. So we'll call on the query object and I'll use whereKey and in this case we'll focus on the locations object. If you remember, the field name is called "location" so we'll do "location" and instead of containedIn, we'll do nearGeoPoint. What this will do is create a list of the closest banks that we can find to the user's location. You can also make it within a certain amount of miles or a certain amount of kilometers by adding a property. In this case we just want the banks that are in our close proximity. In case there are multiples, we'll want to use the limit tag. We can make that equal to 10. The next thing is to extract the data from the Query, so we'll use the findObjectsInBackgroundWithBlock method. This method starts with an opening curly brace. We'll create a variable called objects. It will be cast as AnyObject for now, and once again I'll add an error block. Now we'll test to see if the error is nil. In this case if the error is nil, we're successful. We'll for loop around our objects and use the allBanks NS mutable array, We'll addObject. For each object on each turn of that loop after this, we can use a couple of refresh methods. We'll use the self.tableView reloadData method. We can even add optionally wrapped refreshControl that will end our refreshing. See the code on the next page

95

96 Assignment #8 Build the iOS MyBank App Step - 34
Use Geolocation to find nearest banks Now at this point we can go through the rest of the functionality. That loadData function will be called on the method view did appear. On view did load, we have our refresh control, the same refresh control that was in the transaction controller. When we scroll down we have our traditional Table methods. We have our candidate RowAtIndexPath and editingStyle as well. Note we don’t want to delete the bank from Parse, we'd rather just delete it from the interface so it doesn't show. The locations table is accessible by the public and if we were to delete the bank, then no one would have access to that bank  So now comes the all-important method for tableView. And this is where we pre-populate the data in the cell. I've created a variable called myloc. This is a PFObject that will equal the objectAtIndex of each path as we loop through the table. Next, I'm creating objects called "bankname," "city," and "state." Below that I'm casting it as a String and populating our label.Text with it. Now let’s test. I'm running it in my iPhone. I'm going to the View All Banks button, but nothing shows up? You need to add a key/value pair to the info.plist file (in Xcode, look in the Supporting Files Folder). Click a + to add a new pair, type in NSLocationWhenInUseUsageDescription for Key, Something like Please Allow access to location services for the value. See the next slide for a screen shot. Now let’s really run it. One thing of note, if you want to change your location and customize it for testing in your simulator, click Debug and then Location, go to Custom Location and you can add a Latitude and Longitude. So that's how we use Parse's GeoPoint to create some helpful user functionality for our users.

97

98 To Get Credit for these Assignments
#8 Try uploading your code to github putting a link to the code in the Assignment #8 in Canvas. Or, zip and upload to the assignment. This will be worth 6 points. You can choose to submit this all in one week or if you are having difficulties, spread it over 2. If you choose 2 you must finish through


Download ppt "UMSI 363 Nancy A. Benovich Gilby"

Similar presentations


Ads by Google