문제

I have a custom class I use frequently on my projects. This class has several methods but not all of them are used in every project.

My question is: including this class on a Project will bloat the project with useless code or will the compiler just include the methods used?

I mean, if my class has 30 methods but just 4 are being used in a given project will the compiler include also the other unused 26 or just the 4 used in the final product?

In case it includes all, is there a way to force it to disregard the unused methods and trim the binary to the minimum?

도움이 되었습니까?

해결책

댓글 :

링크는 h.g.muller 가 인터페이스의 현재 유지 관리자입니다. 그의 페이지 구현 해야하는 최소한의 인터페이스를 보여줍니다.

다른 팁

If the other 26 methods have code in @implementation, then yes, they will be used in the final product.

The reason is because of the runtime system. Even if you didn't use that 26 methods in compile time, there's no guarantee they won't be referred in runtime (remember NSSelectorFromString and -performSelector:).

I don't know if there's a way to force remove these code. (-dead_strip doesn't work.)

Sounds like you need to refactor and rename the big fat mamma class.

My question is: including this class on a Project will bloat the project with useless code or will the compiler just include the methods used?

I think you are talking about including the header and implementation of your helper class. This will increase the binary size. As pointed out by jessecurry the linker supports dead-end stripping. This is bad as there's always the possibility someone wants to link with the public api of your binary (fortunately this is not the case as dynamic linking is not allowed on iphone but consider other platforms). But I bet the difference in size is way too marginal to be significant.

The most impact in terms of size is usually the resources you include with your application (images, strings etc.).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top