I need to use a custom "knob" image on a UISwitch. I don't think this is possible with the default SDK. Does anyone know how I might go about this or of any 3rd party libraries that can do this? I've found a few but they are all old and don't work with ARC.
Generally to do something like this you would subclass UIControl. I'm sure there are a bunch of implementations of this particular control type floating around. I found one that you can use here. There is a github link on the page.
By the way, if you find a class you want to use that is not arc enabled, you can either try to convert it yourself (although this will make it harder to download updates for it), or more commonly add the -fno-objc-arc compiler flag to whatever files are not arc compatible and it will exclude them (but you can still use them). More info on that here.
Related
New to Swift, couldn't find an answer to this with a reliable source.
I have some commented code, but would like to know if they are removed when compiled/run in Debug/Release, and if this is enforced or can be turned on/off.
If they are indeed removed, what about those instances where I really need them to be inside, e.g. some framework or something?
Thanks in advance!
If you create inline docs in a swift package, they're available to the consumer. If you provide a Docc asset, that will also be available to the consumer.
If you create a binary, that depends on how it's created and distributed.
Unless there is a security concern not to share the source code, I would do a vanilla SwiftPackage with documentation comments.
I installed pod JSQMessagesViewControllerin my Swift project but now I don't need it any more. I do not want to remove it to cause any side effect. Is it alright if I just leave it there and do nothing? Thanks!
Yes, it won't hurt anything. However, it will make the binary larger than it should be due to unused libraries. Also can be confusing later for others looking at the code why a particular library is there. But, the app will not break because of this.
If you aren't making any reference to this framework it shouldn't cause any side effect if you remove it. I really recommend you to remove anything that is no longer used. It's a good practice to avoid problems with future iOS versions when building your project and also makes your app lighter for users with a quicker download.
Just go ahead and remove the pod.
If you truly do not use it, your project will run without problems.
If you do actually use it without knowing about it, your app will most probably not compile, which is a great time to either remove the reference to the pod, or re-add it if you realize that you actually are using it.
If you do actually use it without knowing about it, your app may compile (e.g. if you refer to it from a xib or a storyboard), but will crash when trying to use the non-existing pod. This is much better than keeping on using the pod without knowing that it affects your project.
Good luck!
I am asking my self if there are a way to add dynamic warning to my project.For exemple, every method in my class should begin by an analytics tag (setTagVorView:), if this line doesn't exists, I or other developers will be notified by a warning on this method.
Today, my only solution is to create a protocol (delegate) with a required method and every class (UIViewController for example) should follow this protocol and implements the required methods. The problem is : if the developer forgot the delegate, he will never be notified.
Another example, the appledoc command line tool add warnings to the project if some properties or methods don't have descriptions.
So how can i add my rules to predict warnings in some cases ?
Thank you.
Not sure if it fits your needs, but there is at least on way, hardcode way to achieve this goal: create a clang plugin and add there your own rules.
I'm not going very deep, because it might take too much time, but if you really interested in this solutions you can take a look at this blog-post, there is actually described a way to make the plugin with custom warnings and even errors
You could use NSAsserts in all the methods you want the developers to override:
NSAssert(NO, #"You need to implement this methode!");
It's, of course, not as elegant as compile time warnings.
Alternatively, you could create a XCode file template,with hardcoded warnings in. Take a look at this SO answer
My company makes a static library for iOS apps. One annoying step for developers is that they have to manually link against all the required frameworks that the library uses, and failing to do so leads to somewhat confusing compiler errors.
I would have previously thought this wasn't possible, but the company Chartboost claims to automatically link against non-default frameworks like AdSupport and StoreKit. Based on my testing in their sample app (available from the linked page), so far this appears to be the case (Even when disabling "Enable Modules" and "Link Frameworks Automatically" in the app that links against the static library).
Is there some way to enable this feature when creating a static library? I've tried enabling modules and the "Link Frameworks Automatically" LLVM options in Xcode, but so far haven't been able to get it working.
There's a piece of code called CBDynamicallyLoadedDependencies that calls dlopen() on the appropriate system library before making the function or method call.
My original answer wasn't correct. the dlopen() call is just in the x86 code. On the device, it's something different, but my ARM assembly isn't strong enough to figure it out. All I can say is that there's a piece of code that's acting as a trampoline to the desired functions and that references the system library files (like /System/Library/Frameworks/AdSupport.framework/AdSupport).
But the point is that it's not a simple project trick that makes it work normally. There's internal code involved.
They might use modules you mentioned and #import instead of #import, which should make the libraries link automatically.
For reference, check this question.
This might not be what you're looking for, but if you don't yet support Cocoapods, I would strongly advise taking a look:
http://cocoapods.org/
(Edit: Cocoapods is essentially linked to Xcode. Other IDEs will need another solution.)
You can advertise Cocoapods to developers as the "easy" way to work with your library, and the manual method as...well, the manual method. ;)
I'm not aware of any industry resistance to Cocoapods, so I don't see a downside to supporting it, and it does solve the problem you're talking about (albeit in a roundabout sort of way).
Also I've found Chartboost VERY developer-friendly. You might even reach out to them and ask.
I'm developing an iOS SDK that integrates other SDKs (Facebook SDK 3.5, for example).
To prevent collisions and allow my customers to import those SDKs as well, I want to rename all of the classes/enums in my code (for example, rename FBSession to RDFBSession, etc).
Is there an easy way to do this instead of going class-by-class and using Xcode's rename feature?
Apple provide a command-line tool called tops(1) that is designed for scripting large-scale code refactoring (renaming C functions, Objective-C methods, classes, and other tokens):
tops -verbose replace "FBSession" with "RDFBSession" Sources/*.[hm]
If you have a lot of replacements, you can put all of the replace... commands into a file that you pass with the -scriptfile option. The man page has more information on the more complex commands/options (and examples).
Xcode also offers textual Search and Replace. This will be faster than individual refactors, but it is ultimately less automated. You can make the step by step refactoring faster by first minimizing the project to the relevant dependencies/sources (if possible).
However, renaming the declarations in a library will not alter the symbol names of its associated binary. If it is distributed with a binary, then renaming will just result in linker errors or (in some cases) runtime errors.
The best idea if you need to use a 3rd party library which your clients might also use is to simply inform them they need to link the library with their app, then publish the version(s) the current release supports so they know they have some extra testing if they go too far ahead with some libraries.
I think that a better approach than simply renaming your classes would be to download Facebook's open source code, rename the classes there and compile a new static library with a set of renamed header files. Then you can be sure that no collisions occur and that you're using symbols that you named yourself.
I must warn you though - working like this may make updating the SDK a nightmare regardless of how you tackle this specific issue.