Routing Design Pattern In Objective-C











up vote
-2
down vote

favorite












I have found good tutorial on Routing design pattern at Swift



Can some one explain it or create it in Objective-C?



GOAL



To jump from one view controller to any other view and vice - versa



Means user can jump at any view to any view using this pattern



https://medium.com/commencis/routing-with-mvvm-on-ios-f22d021ad2b2










share|improve this question
























  • The article code has nothing Swift specific e.g Tuples or generics. The explanation remains the same. The code is more or less a direct language syntax conversion.
    – Warren Burton
    2 days ago















up vote
-2
down vote

favorite












I have found good tutorial on Routing design pattern at Swift



Can some one explain it or create it in Objective-C?



GOAL



To jump from one view controller to any other view and vice - versa



Means user can jump at any view to any view using this pattern



https://medium.com/commencis/routing-with-mvvm-on-ios-f22d021ad2b2










share|improve this question
























  • The article code has nothing Swift specific e.g Tuples or generics. The explanation remains the same. The code is more or less a direct language syntax conversion.
    – Warren Burton
    2 days ago













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I have found good tutorial on Routing design pattern at Swift



Can some one explain it or create it in Objective-C?



GOAL



To jump from one view controller to any other view and vice - versa



Means user can jump at any view to any view using this pattern



https://medium.com/commencis/routing-with-mvvm-on-ios-f22d021ad2b2










share|improve this question















I have found good tutorial on Routing design pattern at Swift



Can some one explain it or create it in Objective-C?



GOAL



To jump from one view controller to any other view and vice - versa



Means user can jump at any view to any view using this pattern



https://medium.com/commencis/routing-with-mvvm-on-ios-f22d021ad2b2







ios objective-c iphone






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 hours ago









Moritz

56.9k19131184




56.9k19131184










asked 2 days ago









9to5ios

3,12522051




3,12522051












  • The article code has nothing Swift specific e.g Tuples or generics. The explanation remains the same. The code is more or less a direct language syntax conversion.
    – Warren Burton
    2 days ago


















  • The article code has nothing Swift specific e.g Tuples or generics. The explanation remains the same. The code is more or less a direct language syntax conversion.
    – Warren Burton
    2 days ago
















The article code has nothing Swift specific e.g Tuples or generics. The explanation remains the same. The code is more or less a direct language syntax conversion.
– Warren Burton
2 days ago




The article code has nothing Swift specific e.g Tuples or generics. The explanation remains the same. The code is more or less a direct language syntax conversion.
– Warren Burton
2 days ago












1 Answer
1






active

oldest

votes

















up vote
-1
down vote













For this kind of flow I use flow coordinators. It just means that in the view controller itself you don't have a hardcoded destination view controller, you just call some delegate (I call him flowDelegate) and this delegate decides what to do next. The sample call would look like this



Obj-C:



@class HomeViewController;

@protocol HomeFlowDelegate

- (void)didTapRegistrationButtonInViewController:(HomeViewController*)viewController;

@end

@interface HomeViewController: UIViewController

@property (nonatomic,weak) id<HomeFlowDelegate> flowDelegate;

@end

@implementation HomeViewController

- (void)registrationButtonTapped {
[self.flowDelegate didTapRegistrationButtonInViewController:self];
}

@end


Swift:



protocol HomeFlowDelegate {
func didTapRegistrationButton(in viewController: HomeViewController)
}

class HomeViewController: ViewController {
weak var flowDelegate: HomeFlowDelegate?

func registrationButtonTapped() {
flowDelegate?.didTapRegistrationButton(in: self)
}
}


The flow delegate can than decide e.g. whether to push new screen or present it modally or do whatever flow would be appropriate.



This approach means that view controllers are independent and can be reused anywhere in the app. You just have to make sure that when a view controller comes on screen it has a flowDelegate assigned.






share|improve this answer























  • The question is clearly asking for an answer in Objective-C, not Swift.
    – rmaddy
    2 days ago










  • Added my approach in Obj-C
    – olejnjak
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350342%2frouting-design-pattern-in-objective-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
-1
down vote













For this kind of flow I use flow coordinators. It just means that in the view controller itself you don't have a hardcoded destination view controller, you just call some delegate (I call him flowDelegate) and this delegate decides what to do next. The sample call would look like this



Obj-C:



@class HomeViewController;

@protocol HomeFlowDelegate

- (void)didTapRegistrationButtonInViewController:(HomeViewController*)viewController;

@end

@interface HomeViewController: UIViewController

@property (nonatomic,weak) id<HomeFlowDelegate> flowDelegate;

@end

@implementation HomeViewController

- (void)registrationButtonTapped {
[self.flowDelegate didTapRegistrationButtonInViewController:self];
}

@end


Swift:



protocol HomeFlowDelegate {
func didTapRegistrationButton(in viewController: HomeViewController)
}

class HomeViewController: ViewController {
weak var flowDelegate: HomeFlowDelegate?

func registrationButtonTapped() {
flowDelegate?.didTapRegistrationButton(in: self)
}
}


The flow delegate can than decide e.g. whether to push new screen or present it modally or do whatever flow would be appropriate.



This approach means that view controllers are independent and can be reused anywhere in the app. You just have to make sure that when a view controller comes on screen it has a flowDelegate assigned.






share|improve this answer























  • The question is clearly asking for an answer in Objective-C, not Swift.
    – rmaddy
    2 days ago










  • Added my approach in Obj-C
    – olejnjak
    yesterday















up vote
-1
down vote













For this kind of flow I use flow coordinators. It just means that in the view controller itself you don't have a hardcoded destination view controller, you just call some delegate (I call him flowDelegate) and this delegate decides what to do next. The sample call would look like this



Obj-C:



@class HomeViewController;

@protocol HomeFlowDelegate

- (void)didTapRegistrationButtonInViewController:(HomeViewController*)viewController;

@end

@interface HomeViewController: UIViewController

@property (nonatomic,weak) id<HomeFlowDelegate> flowDelegate;

@end

@implementation HomeViewController

- (void)registrationButtonTapped {
[self.flowDelegate didTapRegistrationButtonInViewController:self];
}

@end


Swift:



protocol HomeFlowDelegate {
func didTapRegistrationButton(in viewController: HomeViewController)
}

class HomeViewController: ViewController {
weak var flowDelegate: HomeFlowDelegate?

func registrationButtonTapped() {
flowDelegate?.didTapRegistrationButton(in: self)
}
}


The flow delegate can than decide e.g. whether to push new screen or present it modally or do whatever flow would be appropriate.



This approach means that view controllers are independent and can be reused anywhere in the app. You just have to make sure that when a view controller comes on screen it has a flowDelegate assigned.






share|improve this answer























  • The question is clearly asking for an answer in Objective-C, not Swift.
    – rmaddy
    2 days ago










  • Added my approach in Obj-C
    – olejnjak
    yesterday













up vote
-1
down vote










up vote
-1
down vote









For this kind of flow I use flow coordinators. It just means that in the view controller itself you don't have a hardcoded destination view controller, you just call some delegate (I call him flowDelegate) and this delegate decides what to do next. The sample call would look like this



Obj-C:



@class HomeViewController;

@protocol HomeFlowDelegate

- (void)didTapRegistrationButtonInViewController:(HomeViewController*)viewController;

@end

@interface HomeViewController: UIViewController

@property (nonatomic,weak) id<HomeFlowDelegate> flowDelegate;

@end

@implementation HomeViewController

- (void)registrationButtonTapped {
[self.flowDelegate didTapRegistrationButtonInViewController:self];
}

@end


Swift:



protocol HomeFlowDelegate {
func didTapRegistrationButton(in viewController: HomeViewController)
}

class HomeViewController: ViewController {
weak var flowDelegate: HomeFlowDelegate?

func registrationButtonTapped() {
flowDelegate?.didTapRegistrationButton(in: self)
}
}


The flow delegate can than decide e.g. whether to push new screen or present it modally or do whatever flow would be appropriate.



This approach means that view controllers are independent and can be reused anywhere in the app. You just have to make sure that when a view controller comes on screen it has a flowDelegate assigned.






share|improve this answer














For this kind of flow I use flow coordinators. It just means that in the view controller itself you don't have a hardcoded destination view controller, you just call some delegate (I call him flowDelegate) and this delegate decides what to do next. The sample call would look like this



Obj-C:



@class HomeViewController;

@protocol HomeFlowDelegate

- (void)didTapRegistrationButtonInViewController:(HomeViewController*)viewController;

@end

@interface HomeViewController: UIViewController

@property (nonatomic,weak) id<HomeFlowDelegate> flowDelegate;

@end

@implementation HomeViewController

- (void)registrationButtonTapped {
[self.flowDelegate didTapRegistrationButtonInViewController:self];
}

@end


Swift:



protocol HomeFlowDelegate {
func didTapRegistrationButton(in viewController: HomeViewController)
}

class HomeViewController: ViewController {
weak var flowDelegate: HomeFlowDelegate?

func registrationButtonTapped() {
flowDelegate?.didTapRegistrationButton(in: self)
}
}


The flow delegate can than decide e.g. whether to push new screen or present it modally or do whatever flow would be appropriate.



This approach means that view controllers are independent and can be reused anywhere in the app. You just have to make sure that when a view controller comes on screen it has a flowDelegate assigned.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered 2 days ago









olejnjak

263212




263212












  • The question is clearly asking for an answer in Objective-C, not Swift.
    – rmaddy
    2 days ago










  • Added my approach in Obj-C
    – olejnjak
    yesterday


















  • The question is clearly asking for an answer in Objective-C, not Swift.
    – rmaddy
    2 days ago










  • Added my approach in Obj-C
    – olejnjak
    yesterday
















The question is clearly asking for an answer in Objective-C, not Swift.
– rmaddy
2 days ago




The question is clearly asking for an answer in Objective-C, not Swift.
– rmaddy
2 days ago












Added my approach in Obj-C
– olejnjak
yesterday




Added my approach in Obj-C
– olejnjak
yesterday


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350342%2frouting-design-pattern-in-objective-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin