1
  1. I am trying to implement posing for one ios project.
  2. The scenario: Defining class of controller at run time
  3. I realise that poseAsClass or class_poseAs is not available for ios & also deprecated for macOX.
  4. will be grateful to any directions to implement posing in ios. Thanks
Community
  • 1
  • 1
Yogesh Lolusare
  • 2,162
  • 1
  • 24
  • 35
  • This answer will probably help you http://stackoverflow.com/questions/211616/hidden-features-of-objective-c?answertab=oldest#tab-top – Popeye Apr 07 '15 at 08:03
  • try this tutorial http://www.tutorialspoint.com/objective_c/objective_c_posing.htm – Anbu.Karthik Apr 07 '15 at 08:04
  • 1
    Why? What are you actually trying to do? – Wain Apr 07 '15 at 08:21
  • 2
    Posing as another class is exceedingly clever. You should avoid clever code if at all possible, or anyone maintaining your code will forever hate you. It is not available in iOS and deprecated in MacOS X for a reason. – gnasher729 Apr 07 '15 at 08:33
  • Hi @Anbu, the point no. 3 I realise that poseAsClass or class_poseAs is not available for ios & also deprecated for macOX. i followed tutorialspoint.com/objective_c/objective_c_posing.htm, http://stackoverflow.com/questions/211616/hidden-features-of-objective-c?answertab=oldest#tab-top & then only came to point no.3. Thanks – Yogesh Lolusare Apr 07 '15 at 08:36
  • Hi @wain, The pointNo.2 The scenario: Defining class of controller at run time states the reason why i want to implement – Yogesh Lolusare Apr 07 '15 at 08:37
  • Hi @gnasher, Your comment sounds like answer to my query. Thank you – Yogesh Lolusare Apr 07 '15 at 08:41
  • Why negative marking please atleast let me know the reason which will help me to improve. This question makes difference to me. – Yogesh Lolusare Apr 07 '15 at 08:45
  • @Yogesh.Lolusare.Apple chances are someone who downvoted it, is not in the comments. – Shamas S Apr 07 '15 at 08:46
  • on object level you could use isa-swizzlig http://stackoverflow.com/questions/15060629/dynamically-change-an-objects-superclass – vikingosegundo Apr 07 '15 at 08:58
  • Hi @vikingosegundo, Yes, this can be answer, please write in the answer section if you think this can be the answer. Thanks – Yogesh Lolusare Apr 07 '15 at 08:59
  • Sounds like you should be using @protocol and logic to decide how to fill the protocol. – Wain Apr 07 '15 at 09:02
  • Hi @wain, can you please elaborate this in answer section. Thanks – Yogesh Lolusare Apr 07 '15 at 09:04

2 Answers2

3

The whole pose / swizzle approach is really useful if you want to tamper with the OS / private SDK supplied classes - but you generally shouldn't be doing that and it's not a good idea to use it as a standard approach in your own code.

The scenario: Defining class of controller at run time

You would usually do this by using an abstract superclass / interface / @protocol to define the interface that your potential controllers need to implement and then switching them in and out at runtime.

In your case it seems that you would have one controller which acts as a proxy for the true controller. You also don't technically need an @protocol because UITableViewController is effectively your abstract superclass, but it would be best for your proxy to be a UITableViewController and own the view and for your other controllers to be NSObject subclasses and simply conform to the UITableView DataSource/Delegate protocols.

Wain
  • 118,658
  • 15
  • 128
  • 151
1

You should look into Method Swizzling. It helps you change the functions/function bodies at run time.

There is a great tutorial here.

Shamas S
  • 7,507
  • 10
  • 46
  • 58
  • 1
    No i want to change the target class, any way thanks. – Yogesh Lolusare Apr 07 '15 at 08:42
  • 1
    @Yogesh.Lolusare.Apple posing would make your customClass get functions instead of UIViewController class, right? swizzling would do something like that as well, except just for the functions. – Shamas S Apr 07 '15 at 08:48
  • @oh i think i need to work more on method swizzling. Thanks for your vital comments. i will mark this as accepted answer, once i get my experiments on this done. Thanks, if possible can you please also look into http://stackoverflow.com/questions/29424934/defining-class-of-controller-at-run-time – Yogesh Lolusare Apr 07 '15 at 08:50
  • I don't know the reason why one is down voting the answer & question. – Yogesh Lolusare Apr 07 '15 at 08:54
  • 1
    @Yogesh.Lolusare.Apple don't worry about the downvotes. Sometimes people just aren't paying enough attention. :) – Shamas S Apr 07 '15 at 08:55
  • Ya, using power to distract – Yogesh Lolusare Apr 07 '15 at 08:56