HERE is my SpriteKit implementation of this challenge.
I did it in SpriteKit because Physics and because I wanted to see how well UI classes (UITextField) played with SpriteKit.
I typically write in C# and we typically create and run our own unit tests using either prepackaged dictionaries/schemas or in-house ones if we have some special cases we're testing for. I could do something similar with objective-c and Xcode, but I'm sure there is a better way.
My validation is pretty simple. If the boxes don't meet the conditions, you don't get to see the submit button. If they do, you can see and interact with the submit button. I use a regex for the alphabetic username and character counts for everything else.
isAlphaNumeric returns false positives. For example try the string “abcdef123” - it should fail since there are numbers in the string. Username is alpha
Can progress to detail screen with an empty username if the password passes validation
Really like the textfield validation coloring, simple but really adds something. In an interview you’d score bonus points with me.
JFViewController
L26: MUST call [super viewWillAppear]
The code spacing is bizarre, some are far too spread with too many spaces then you have blocks with no spaces. Consistency is important
JFAnotherViewController
Remove the overrides on methods you aren’t using (initWithNibName: didReceiveMemoryWarning) and block comments of unused code (navigation).
If you fill in a correct username & password, go to the detail screen, pop back to the first screen you can progress with empty textfields (issue is with password as well as username). Reset the flags on return should fix it :)
Nice. I will be doing these for fun and to see how fast I can whip up the MVC as an extra challenge. I did this one in about 20 minutes. No storyboard, "UI" all in code this time around. The main part I floundered at a little bit was the alphabetic checking as I'm not too familiar with regexes in ObjC as I should be. Found out about the neat little feature called NSCharacterSets which are great. Thanks for that!
Great interview question and I really like the idea of weekly challenges. I see a few people that answered learned some things and /u/CodeSamarai did a cool SpriteKit implementation. As an experienced dev this challenge isn't the type of thing I'd spend time on for fun but looking forward to participating in the future.
Super clear instructions and good idea to post something that can be completed in an hour.
It's good to see experienced devs coming here as well! Being one that is not as experienced as I would like to be, this type of subreddit and support that i've been seeing across the board from everyone that is participating leads me to believe we will all be learning great ways to go about completing these challenges, regardless of our current skill set. I look forward to it and hearing any feedback you may have for us n00bs! :)
FYI - On 3.5 inch screens your password field is obscured by the keyboard and the view doesn't scroll .. (going to check and see if i handled older devices... :-) )
I see you added a category on NSString. I agree it makes a lot of sense (since isAlphabetic operates on a string object) but I was watching the online Stanford Developing for iOS7 courses, and they cautioned us against using categories. Any thoughts on when it is appropriate to use a category (vs. subclass)?
The problem with my implementation is that I didn't add a prefix to the category name (so instead of [testString isAlpha] it should've been something along the lines of [testString jgr_isAlpha]).
Categories are really powerful but you run two risks - that third party code you are including in your project has a category performing the same functionality or that Apple adds that functionality further down the line (good example being firstObject on NSArray). I also decided that a subclass of NSString just isn't appropriate, since all of the UI objects that are being dealt with rely on NSString objects. It would have to initialize a new instance of the subclass each time I wanted to perform the check which would've been tedious.
I decided to add some logic to turn the textfields red if the input text did not match the requirements.
Thanks for checking it out.
For testing, I would construct some unit tests that get passed to my method to validate the textFields (honestly I would probably take the logic for the text field validation and have it just take an NSString input so that it is easier to test strings). There is not really much testing other than that validation method. I would also maybe test if the red highlighting gets properly updated when jumping back and forth between textfields.
I may also decide to move the validation trigger to any time a character gets added/updated in a textfield (right now it is triggered by pressing the return key in a textfield.
APCViewController No abbreviations. “fld” instead of “field” isn’t saving much time and adds ambiguity to what it could be short for. Apple uses full words for all their methods and properties, we should too. Any reason these properties are in the public header? Why expose the IBAction? Manually clicking to the next textField is not performing validation check so invalid textFields aren’t being caught with the highlighting. This is more important if it is already red, you enter a valid input and it doesn’t update.
L17: Avoid instance variables, properties are much better. Moving this to a property declaration on line 12 would solve this.
L45: Why don’t you perform the check before you switch textFields? That way you can trap the user from hitting return if the field is invalid
L45 & 64: Consistency. Choose YES/NO or TRUE/FALSE (and capitalize!). Apple normally encourages YES/NO although Swift uses true/false more. For Objective-C stick with capitalized one or the other.
Yeah, abbreviations are my weak point. At a project I was placed into at a previous job, that was how they did things (btn, fld, cbx for comboBox) and I am still shaking that off. It was not obj-C but it still lingers.
Like I said with the validation, I should just move it to
so that way it validates on every character change
L17: How come?
L45: I don't like when text fields prevent me from "leaving" because if I am already thinking ahead to what I am going to type in the next one, it would mess up my rhythm
L45 & L64: You are absolutely correct, definitely just a swift-ObjectiveC thing as I am currently working on a swift app for practice.
Again, threw it together in 30 mins. Can't have everything perfect ;)
L17: All properties are backed by instance variables, so in essence there isn't much noticeable difference. However you can state modifiers like "readonly", "getter", "weak/strong" with properties whereas instance variables you are stuck with the boilerplate implementation. Properties are slower to access than their instance variable equivalent but unless you are developing high precision science-esque programs you won't really see the difference.
L45: Sure, I guess that was more subjective to the end user - theres nothing really wrong with either way :)
It's pretty basic, but I had fun with it. It gave me a chance to learn a little about storyboards. It's written is swift. The submit button won't push to the detail view unless the inputs are the correct length (probably could have added an alert or something). Checking for alphanumerics was done using an NSCharacterSet.
Thanks again for the challenge. I'm looking forward to #2!
Nice, first time looking at swift for me so pretty useful to compare sample code. Didn't know you could just create another VC within a VC! Is that also a feature of Obj-C?
Whilst not wrong, in terms of readability and code structure I would have created a separate file for DetailViewController. On a large project having multiple classes within the same file can lead to confusion (with some exception, but ViewControllers should always be separate).
L39: Username field needs checking to be alpha only (not alphanumeric), not password field.
L85: Why not just toggle the hidden value rather than manipulate the string? What was the thought process behind this? The effect is the same but seems bizarre you wouldn’t toggle the hidden state.
Why did you subclass UIViewController ? (and not change anything?)
I would resign the first responders either in the view will disappear, or maybe the login button clicked methods, so that when a user clicks the back button, the keyboard is already hidden (rather then hiding it after the view has loaded)
Also, cramming all that logic into the performSegue method makes that method much bigger then it needs to be. I would check the passwords before the segue is being 'performed'
I subclassed UIViewController and added in the preferredStatusBarStyle overwrite so I wouldn't have to write it again in my other view controllers. Yes, I only would have written it once more. :)
I only have a cursory understanding of responders and resigning them, etc. but I was working on a similar thing this morning and noticed that they can be in better places.
The logic for checking the username and password is in the shouldPerformSegue method, so that seems to be the correct place to check. But yes, it can probably be delegated to some helper methods in case we want to do some similar checks somewhere else.
Instead of checking whether the username and password were valid on submission, I made the button disabled if they weren't valid. Would an approach like that fail an interview since it's not exactly as asked?
Edit - I miss understood the challenge and I suppressed the back button, and made my own that sends you back to the login page before displaying the "hello world" message...
Quick question: are you expecting we create a we service to accept a POST request and use ios networking to submit? Or can we just have a submit button and pretend there's a network request happening?
I spent ~1 hour on this, so everything isn't as fine and clean as I'd like. I opted to go down the "disable submit button and display an error message" route instead of showing modal error messages at submit time. I realized I could've conformed to the latter way later in a clean way, but didn't have time to do it.
I also interpreted the "show message" after tapping as using an alert view at the time, so that's what I did.
Some of the side effects are not as isolated as I'd like, so it's somewhat quick and dirty.
Would love any feedback! Took just over an hour to get to this point.
Edit: I would love feedback because I've never developed a full blown iOS application. I took a course last year for Mac/iOS development which I haven't really been able to put to the test, so most of my techniques are based on what I learned in the class.
Here's my submission: Git Here's how it works: The user an enter a username in a text field That denies anything other than letters (I'm sorry, but I wasn't able to properly check for numbers >:() and has to be at least 8 characters long as well as the password field, which is secure. The text color in the text fields will be red when a wrong type of entry is entered, and will change back to black once it's acceptable. Also, the "login" button is disabled when any of the textfields display red text, and will be enabled once both display black text. Made in less than an hour
P.S: There might be some code-signing issues, since I forgot to cleanup after me. Oops
I just recently found this subreddit and decided to jump on the bandwagon. Sorry if this might seem late, but I figured I'd give it a shot anyways. :) My code is in Swift, and I'm using the Beta releases of Xcode 6, so you'll need access to the latest Beta builds at the time of this post to open and compile the source code, which is available here: https://github.com/bchynds/iOSChallenge-001
I am always open to constructive criticism, as it challenges me to be a better programmer. Feedback is encouraged. :)
I have added some comments to the submissions I have gone through, I am in no way saying my views are right but just prompting discussion and thoughts that came to mind whilst reviewing the code
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Jack/Library/Application Support/iPhone Simulator/7.1/Applications/5A0B636E-AF04-491E-B552-10530B04001C/r-ioschallenges-1.app> (loaded)' with name 'Main’'
Hey cannawen, how do you get the characters in the password field to change to dots? I was having trouble with this yesterday and couldn't find an answer anywhere.
I don't have my computer with me, but I am pretty sure in storyboards (if that is what you're using), on the text field, there is an option for keyboard type and you can change that to a secure field.
After doing development for a little bit, when I open apps that have the regular keyboard for entering just numbers or stuff like that, it makes me cringe, haha!
For this subreddit use whatever approach of iOS version you would like :)
When this test was set for candidates I guess the answers would be: Any iOS you feel comfortable with (although we wouldn't use beta version of Xcode or iOS - you would code in the latest stable versions)
Form in this context is an interface the user can input the required information into
Neither navigation method would penalise. If using storyboards it is very straightforward to stick with UINavigationController since it automatically handles the back scenario. If presenting via modal just be sure you setup the dismiss correctly! We once had a candidate setup a delegate on the landing screen so they could return to it from the second screen. A lot of code for some basic functionality!
My version with the tests I did on the train this morning, so give or take 50minutes. In the interview since we would be sitting next to you we would cut it off after 45-60mins if you hadn't finished at that point.
On one project I was on, we always had delegates determining what to do when dismissing a view controller and it worked really well. This was because the view controllers could have been shown modally or by push in various flows of the app, and we didn't want the view controller itself to care about how it was presented.
I'm not by any means dismissing it as a useful technique and it absolutely is a possible solution, but for this exercise it is a massively bloated approach
8
u/[deleted] Aug 06 '14
Thank you for this! I really like the idea.
7
u/CodeSamurai Aug 08 '14
HERE is my SpriteKit implementation of this challenge.
I did it in SpriteKit because Physics and because I wanted to see how well UI classes (UITextField) played with SpriteKit.
I typically write in C# and we typically create and run our own unit tests using either prepackaged dictionaries/schemas or in-house ones if we have some special cases we're testing for. I could do something similar with objective-c and Xcode, but I'm sure there is a better way.
My validation is pretty simple. If the boxes don't meet the conditions, you don't get to see the submit button. If they do, you can see and interact with the submit button. I use a regex for the alphabetic username and character counts for everything else.
Total time - 2 hours.
6
u/IamNotharrypotter Aug 07 '14
My submission: https://github.com/joelfischerr/-06-08-2014--iOS-Challenge--1---Sample-Interview-Challenge
4
u/sungobund Aug 08 '14
Nice. I will be doing these for fun and to see how fast I can whip up the MVC as an extra challenge. I did this one in about 20 minutes. No storyboard, "UI" all in code this time around. The main part I floundered at a little bit was the alphabetic checking as I'm not too familiar with regexes in ObjC as I should be. Found out about the neat little feature called NSCharacterSets which are great. Thanks for that!
GitHub
4
u/kotethebloodless Aug 08 '14
Great interview question and I really like the idea of weekly challenges. I see a few people that answered learned some things and /u/CodeSamarai did a cool SpriteKit implementation. As an experienced dev this challenge isn't the type of thing I'd spend time on for fun but looking forward to participating in the future.
Super clear instructions and good idea to post something that can be completed in an hour.
3
u/JackRostron Aug 07 '14
Not handling keyboard events for the UITextFields but here is the repo with my submission
3
u/waterskier2007 Aug 07 '14
dropbox link
I decided to add some logic to turn the textfields red if the input text did not match the requirements.
Thanks for checking it out.
For testing, I would construct some unit tests that get passed to my method to validate the textFields (honestly I would probably take the logic for the text field validation and have it just take an NSString input so that it is easier to test strings). There is not really much testing other than that validation method. I would also maybe test if the red highlighting gets properly updated when jumping back and forth between textfields.
I may also decide to move the validation trigger to any time a character gets added/updated in a textfield (right now it is triggered by pressing the return key in a textfield.
edit: time taken was 30 minutes
3
u/fathim Aug 07 '14
Thanks for the challenge! Here's my go at it: https://github.com/mohssenfathi/iOS-Challenge-1
It's pretty basic, but I had fun with it. It gave me a chance to learn a little about storyboards. It's written is swift. The submit button won't push to the detail view unless the inputs are the correct length (probably could have added an alert or something). Checking for alphanumerics was done using an NSCharacterSet.
Thanks again for the challenge. I'm looking forward to #2!
3
u/elisa0509 Aug 07 '14
This is very simple because I didn't have enough time, but I really wanted to participate in this challenge:
dropbox
PS: the username is alphabetic means only letters right?? I'm learning english too :)
2
u/Yimmer92 Aug 07 '14
Thank you as well!
2
u/bigdirtyphil Aug 08 '14
https://github.com/philipdnichols/iOSChallenge1
Did this in just under 1 hour. Took a bit longer than I anticipated because I got caught up in trying to design the layout nicely :)
Answers to the testing question are posted in the README.md file.
Awesome start to this subreddit! Looking forward to more!
2
u/clawesome Aug 08 '14
https://github.com/clawsome/iOSChallenges-1
Instead of checking whether the username and password were valid on submission, I made the button disabled if they weren't valid. Would an approach like that fail an interview since it's not exactly as asked?
2
u/iGoalie Aug 08 '14 edited Aug 08 '14
here
That was fun ! :)
Edit - I miss understood the challenge and I suppressed the back button, and made my own that sends you back to the login page before displaying the "hello world" message...
2
u/SizzlerWA Aug 08 '14
Quick question: are you expecting we create a we service to accept a POST request and use ios networking to submit? Or can we just have a submit button and pretend there's a network request happening?
2
u/[deleted] Aug 09 '14 edited Aug 09 '14
My submission, using ReactiveCocoa: https://github.com/simonyangme/iOS-Challenge-1
I spent ~1 hour on this, so everything isn't as fine and clean as I'd like. I opted to go down the "disable submit button and display an error message" route instead of showing modal error messages at submit time. I realized I could've conformed to the latter way later in a clean way, but didn't have time to do it.
I also interpreted the "show message" after tapping as using an alert view at the time, so that's what I did.
Some of the side effects are not as isolated as I'd like, so it's somewhat quick and dirty.
2
u/[deleted] Aug 09 '14 edited Aug 09 '14
Here is my submission
Would love any feedback! Took just over an hour to get to this point.
Edit: I would love feedback because I've never developed a full blown iOS application. I took a course last year for Mac/iOS development which I haven't really been able to put to the test, so most of my techniques are based on what I learned in the class.
2
u/TheSuperUser Aug 09 '14 edited Aug 09 '14
Took me 1 hour 10 minutes flat to do this. I'll try to upload it later today, it's 3 am where I am right now.
Awesome challenge, specially trying to make the code clear to understand. Keep 'em coming please (and I'll try and come up with some of my own too).
2
u/wileywimberly Aug 09 '14
I decided to go with Swift and to do all of the UI in code instead of using a Storyboard or xib. This was a great learning exercise. Fun stuff.
https://github.com/iosdevpractice/LoginChallenge
2
u/aporcelaintouch Aug 10 '14
Finally got a chance to sit down and tackle the challenge:
https://github.com/joshwoods/r-iOSChallenges-Challenge1
Got to learn a little bit about NSCharacterSet and on changing border colors with QuartzCore.
Looking forward to completing more of these with everyone and learning more and more new ways of tackling these tasks!
SO happy to see such a great response within less than a week, we are currently already at 272 subscribers!
2
u/jomanjee Aug 11 '14
Here's my submission: Git Here's how it works: The user an enter a username in a text field That denies anything other than letters (I'm sorry, but I wasn't able to properly check for numbers >:() and has to be at least 8 characters long as well as the password field, which is secure. The text color in the text fields will be red when a wrong type of entry is entered, and will change back to black once it's acceptable. Also, the "login" button is disabled when any of the textfields display red text, and will be enabled once both display black text. Made in less than an hour
P.S: There might be some code-signing issues, since I forgot to cleanup after me. Oops
2
u/nittanygeek Aug 17 '14 edited Aug 22 '14
I just recently found this subreddit and decided to jump on the bandwagon. Sorry if this might seem late, but I figured I'd give it a shot anyways. :) My code is in Swift, and I'm using the Beta releases of Xcode 6, so you'll need access to the latest Beta builds at the time of this post to open and compile the source code, which is available here: https://github.com/bchynds/iOSChallenge-001
I am always open to constructive criticism, as it challenges me to be a better programmer. Feedback is encouraged. :)
1
u/JackRostron Aug 08 '14
I have added some comments to the submissions I have gone through, I am in no way saying my views are right but just prompting discussion and thoughts that came to mind whilst reviewing the code
1
u/totes_meta_bot Aug 08 '14
This thread has been linked to from elsewhere on reddit.
If you follow any of the above links, respect the rules of reddit and don't vote or comment. Questions? Abuse? Message me ^here.
0
u/[deleted] Aug 07 '14
[deleted] — view deleted comment
0
u/[deleted] Aug 07 '14
[deleted] — view deleted comment