Accessing Method from other Classes Objective-C

前端 未结 8 1523
挽巷
挽巷 2020-11-29 05:57

Looked for an answer for this question, but I haven\'t found a suitable one yet. I\'m hoping you guys (and gals) can help me out! (This is for an iPhone app)

Alrig

8条回答
  •  迷失自我
    2020-11-29 06:50

    Bear in mind that Objective-C is just a superset of C, and that whilst #include directives are mostly used for header files, there's nothing stopping you using a #include to embed the contents of one implementation inside another implementation. If the code is truly identical, you can easily just stick it in its own file, and #include it in the .m file.

    Having said that, perhaps it would be better to use this technique in conjunction with categories, especially if the same implementation has similar behaviours.

提交回复
热议问题