mia
mia

Reputation: 383

Weak Linking in IOS

I just want to confirm when to weak link in IOS

Case 1: A totally new framework.
Solution: Weak link the framework if you need to support previous versions and handle that gracefully in code. This is fine.

Case 2: Existing framework and class but new selector addition and you are using this new selector.
Solution: No need to weak link . Just check if respond to selector and handle the code. This is also fine.

Case 3: Existing framework but new class added and you are using this new class.
Solution: Weak link the framework if you need to support previous versions and handle that gracefully in code . is this correct ??

I tried and confirmed case 1 and 2. For case 3 i tried using UIStepper class but unfortunately it was hidden in previous implementation :-), so couldn't confirm.

see the following link: UIStepper not shown but did not crash in 4.3 simulator

Thought of leaving the question to GURUs for a quick answer.

Please confirm case 3

-mia

Upvotes: 1

Views: 1285

Answers (1)

一二三
一二三

Reputation: 21249

For case 3 (new class in an existing framework), you do not need to weak link to the framework, but you will need to use NSClassFromString to get a reference to the Class in order to create instances of it (and remember to handle the case where it returns nil on older versions of iOS).

Upvotes: 2

Related Questions