Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HACK WEEK] Example Swift App with UI and Unit Test targets [SWIFT 1.1, Xcode 6.2 rel] #27

Merged
merged 46 commits into from
Mar 31, 2015

Conversation

mpkeefe
Copy link
Contributor

@mpkeefe mpkeefe commented Mar 24, 2015

Demonstrates use of NYTPhotoViewer from an app written in Swift with UI and unit tests

  • Note that this PR includes a workaround for the iPad issue in which tapping Share from the built-in NYTPhotosViewController causes a crash. Although the crasher will be fixed in the underlying pod, the workaround provides a simple demonstration of passing a closure that would otherwise be unnecessary.
  • Minimum deployment target is 8.2 (current release as of initial pull request).
  • This version supports the Swift 1.1 feature set (using a singleton for the provider) avoiding language improvements still in beta.
  • Requires Xcode 6.2 release SDK to build and run. Clone this repo, open the workspace under the Example folder and set the scheme to NYTPhotoViewer-Swift.

@mpkeefe
Copy link
Contributor Author

mpkeefe commented Mar 24, 2015

Hey @bcapps @Twigz , @cdzombak @mliberatore @jasonhawkins @yorkepb I've downgraded this NYTPhotoViewer example app and unit tests to support Swift 1.1 from Xcode 6.2. I'll be keen to hear any comments or suggestions you have.

var placeholderImage: UIImage?
var attributedCaptionTitle: NSAttributedString
var attributedCaptionSummary: NSAttributedString
var attributedCaptionCredit: NSAttributedString
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these 5 properties are only set in the initializer, can we declare them let instead of var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reduced 5 down to 2: image and attributedCaptionTitle are still variable. The compiler won't let me assign to those two, even in the init() if they are declared as constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was looking at a different error message. Yes we are allowed to assign an initial value during initialization to a constant property that does not already have a default property value. Dow to 1 variable that does get modified after initialization.

@cdzombak
Copy link
Contributor

Where did the "Testing" test image come from? If we plan to release this publicly, we should ensure we have some right to use that image.


class ViewController: UIViewController, NYTPhotosViewControllerDelegate {

@IBOutlet weak var imageButton : UIButton!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIButton?, please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I meant to change this after our conclusion on the other PR!
Done.

@bcapps
Copy link
Contributor

bcapps commented Mar 26, 2015

@cdzombak It's the one that was already in the project, and it comes from a Google search with the "Labeled for reuse" Usage Rights filter. Looking at it more closely, though, I can't actually find the original source and accompanying license, so Google may have been mistaken.

But this brings up a good point - why was the asset catalog re-added?

@cdzombak
Copy link
Contributor

Aside from the stuff I called out, this looks fine to me.

@@ -111,8 +111,8 @@ - (NSDictionary *)photosViewController:(NYTPhotosViewController *)photosViewCont
return nil;
}

- (void)photosViewController:(NYTPhotosViewController *)photosViewController didDisplayPhoto:(id <NYTPhoto>)photo {
NSLog(@"Did Display Photo: %@ identifier: %@", photo, @([self.photos indexOfObject:photo]).stringValue);
- (void)photosViewController:(NYTPhotosViewController *)photosViewController didDisplayPhoto:(id<NYTPhoto>)photo atIndex:(NSUInteger)photoIndex {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after id

@mpkeefe
Copy link
Contributor Author

mpkeefe commented Mar 26, 2015

Thanks for taking the time @cdzombak !!

@mpkeefe
Copy link
Contributor Author

mpkeefe commented Mar 26, 2015

@bcapps I've shared the original asset catalog in a common group/folder and removed the copy.


@IBOutlet weak var imageButton : UIButton?
private let photos = PhotosProvider().photos
private var photosViewController: NYTPhotosViewController
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original intention of the sample project was to mimic how we thought the view controller would be used in most applications. It seems unlikely to me that apps would have a property for a view controller that they will present in the future and that they would initialize that view controller this early, in the initializer. It seems more likely, to me at least, that they would create and instantiate a view controller at the time they need to display it - in this case, when the image is tapped. The Objective-C version of the sample app instantiates the view controller without storing a property when the image is tapped, and I think that it makes a bit more sense and is closer to how people would usually use it in their apps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, fixed in the next commit.

@mpkeefe
Copy link
Contributor Author

mpkeefe commented Mar 31, 2015

@cdzombak You should find your UX weirdness is fixed!

@mpkeefe
Copy link
Contributor Author

mpkeefe commented Mar 31, 2015

Okay @bcapps, have another look

@cdzombak cdzombak assigned cdzombak and unassigned mpkeefe Mar 31, 2015
@cdzombak
Copy link
Contributor

@cdzombak You should find your UX weirdness is fixed!

@mpkeefe looks good from here. Which commit fixed the issue? (If it was aa27285 , this might expose a bug—while that usage might be uncommon, it is certainly a valid way to use a view controller.)

cdzombak added a commit that referenced this pull request Mar 31, 2015
[HACK WEEK] Example Swift App with UI and Unit Test targets [SWIFT 1.1, Xcode 6.2 rel]
@cdzombak cdzombak merged commit d0d70d2 into develop Mar 31, 2015
@cdzombak cdzombak deleted the feature/example-app-swift-1.1 branch March 31, 2015 15:48
@mpkeefe
Copy link
Contributor Author

mpkeefe commented Mar 31, 2015

@cdzombak Yes, that commit resolved Brian's concern and took care of all the weirdness you reported: wrong background color, wrong initial view origin, etc. It looked as though the view controller was being instantiated twice, but I haven't verified this so I could be mistaken.

@cdzombak
Copy link
Contributor

@mpkeefe thanks! I filed #39 to remind me/someone to followup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants