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

Update to Swift 3 #40

Merged
merged 17 commits into from
Oct 13, 2016
Merged

Update to Swift 3 #40

merged 17 commits into from
Oct 13, 2016

Conversation

onmyway133
Copy link
Contributor

@onmyway133 onmyway133 commented Oct 3, 2016

  • Find this a bit strange NSWorkspace.shared().open(url) vs UIApplication.shared.openURL(url)

@mention-bot
Copy link

@onmyway133, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vadymmarkov, @zenangst and @jessearmand to be potential reviewers.

}
}

extension MutableCollectionType where Index == Int {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have a hard time extending MutableCollection, so extend on Array for now

@@ -11,7 +11,7 @@ public protocol Routable {

public protocol ErrorRoutable {

func handle(routeError: ErrorType, from currentController: Controller)
func handle(_ routeError: Error, from currentController: Controller)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave routeError in function signature, or maybe just error.

@@ -42,10 +42,10 @@ public struct Compass {
return nil
}

static func parseAsURL(url: NSURL, payload: Any? = nil) -> Location? {
static func parseAsURL(_ url: URL, payload: Any? = nil) -> Location? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe parseAsUrl?

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 think that parseAsURL is actually dealing with url components, so I rename it to parseComponents

@@ -94,8 +94,8 @@ public struct Compass {

extension Compass {

public static func navigate(urn: String, scheme: String = Compass.scheme) {
guard let url = NSURL(string: "\(scheme)\(urn)") else { return }
public static func navigate(_ urn: String, scheme: String = Compass.scheme) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe navigate(to urn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense

return components != [""] ? components : []
}

func replace(string: String, with withString: String) -> String {
return stringByReplacingOccurrencesOfString(string, withString: withString)
func replace(_ string: String, with withString: String) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just a syntactic sugar

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but it makes less sense in Swift 3 I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, lets get rid of the Sugar that are fixed by Apple in Swift 3.

Copy link
Contributor

Choose a reason for hiding this comment

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

@onmyway133 Would you mind to remove this functions an use replacingOccurrences(of: string, with: withString) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

@@ -7,13 +7,13 @@
#if os(OSX)
public typealias Controller = NSViewController

func openURL(URL: NSURL) {
NSWorkspace.sharedWorkspace().openURL(URL)
func openURL(_ url: URL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think func open(url: URL) is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

Putting the _ seems to be the default everywhere tho. Which is a bit stupid, since, if everyone needs underscore, why don't we delete the underscore.

Copy link
Contributor

Choose a reason for hiding this comment

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

@RamonGilabert I think the idea is to move the last part of the function's name to be an argument name, like in the example above (like in good old Objective C times) So we have to use _ as less as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, sorry, I thought you suggested func openURL(url: URL).

}
#else
public typealias Controller = UIViewController

func openURL(URL: NSURL) {
UIApplication.sharedApplication().openURL(URL)
func openURL(_ url: Foundation.URL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need Foundation here.

@onmyway133
Copy link
Contributor Author

Fixed as you suggest @vadymmarkov 😉

@@ -18,21 +18,21 @@ public struct Compass {

public static var routes = [String]()

public static func parse(url: NSURL, payload: Any? = nil) -> Location? {
let path = url.absoluteString.substringFromIndex(scheme.endIndex)
public static func parse(_ url: URL, payload: Any? = nil) -> Location? {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave it like public static func parse(url: NSURL, payload: Any? = nil). Thought? @onmyway133 @zenangst @RamonGilabert ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, remove _. I like labels :)

@@ -15,4 +15,6 @@ Pod::Spec.new do |s|

s.source_files = 'Sources/**/*'
s.frameworks = 'Foundation'

s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

@vadymmarkov
Copy link
Contributor

I've started a GitHub review here and now it's hard to read this PR tbh, it's not clear what is fixed and what is not 😞 But there are 2 comments waiting for your reply @onmyway133 😄

@@ -5,13 +5,13 @@
#endif

#if os(OSX)
public typealias Controller = NSViewController
public typealias CurrentController = NSViewController
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We preserve Controller for another use case?

Copy link
Contributor

Choose a reason for hiding this comment

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

I had a conflict with Controller in Spots so I decided to change this one to no "kidnap" the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zenangst oh ja, because we have struct Compass so the namespace is lost

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should try and fix that thing, now is probably a good idea to address it as we are already doing some breaking changes in the migration. (breaking as in having to adopt new Swift 3 syntax).

@zenangst zenangst merged commit d5833d6 into master Oct 13, 2016
@zenangst zenangst deleted the swift-3 branch October 13, 2016 10:31
@zenangst zenangst mentioned this pull request Oct 13, 2016
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.

5 participants