r/ObjectiveC • u/nimata • Aug 26 '16
FCAlertView: A Beautiful, Flat & Customizable Alert for iOS
http://www.github.com/nimati/FCAlertView
10
Upvotes
r/ObjectiveC • u/nimata • Aug 26 '16
3
u/rifts Aug 27 '16
This looks awesome!
2
u/purpleWheelChair Aug 26 '16
Nice, looks cool.
1
u/[deleted] Sep 20 '16 edited Sep 20 '16
Where to begin.
I don't mean to sound harsh but this code illustrates a lot of incorrect approaches and defines "how not to do this."
I gasped in shock when I saw this going on in your drawRect:
alertViewContents = [[UIView alloc] initWithFrame:alertViewFrame]; [self addSubview:alertViewContents];
And then about a thousand lines of buildup code. Why are you using drawRect to essentially build your whole user interface? This is for your init code. Furthermore you don't do layout in drawRect: ... you can override layoutSubviews and then do specific layout there. The current "correct" way to do this anyway is by setting up constraints, and you can do that in your init. if you don't want to do constraints, you can use autoresizing easily enough for this. If you don't want to do that then override layoutSubviews and lay your view out there.
Without going any further...
This is as an implementation, in fact "completely wrong."
Your view really looks beautiful but what you're doing here is not code that should be shared with other people so as not to give them ideas on how to implement so poorly. This is a hackjob that maybe shows what you want it to do on the surface but is not going to play nicely with anything and has bombs waiting to blow up on people.
As a beginning for you to fix this and do it right:
As a side note things like this are just bad bad bad code:
The purpose of this function is to load a class object that you are not aware of at compile time. So you can get a string from any input and then check to see if it's a class or create instances of that class and so on. Whatever code this was borrowed from looks to me like something someone intended to be portable between iOS6 and iOS7 and was cleverly trying to test what he was running on before he made decisions about using the class.
The rest of this is not iOS6 safe I don't think so there is no point in checking this, the function is going to return a class every time. This code will not in fact even compile if the test were to fail, since it uses the exact class name at compile time after testing it dynamically to exist in the runtime.
Basically if you can type the class name in, and Xcode lets you compile it, then NSClassFromString is going to return a valid class. So this is completely pointless as a test.
What it is doing though is just burning resources, it has to take a class name as a NS string, convert that into a C string, hit a hash table and look up the class at runtime then return it to you. For a test that literally never fails, it is just waste.
So, with respect, you need to go back to the drawing board and study how to implement before giving your code out like this.
3
u/SparksCatcher Aug 27 '16
Awesome!
0
u/[deleted] Aug 27 '16
[deleted] — view deleted comment