Tag: cocoa

Require type and protocol for method parameter

I am playing around with Swift and am stumbling over the following problem: given I have the predefined class Animal: //Predefined classes class Animal { var height: Float = 0.0 } I now write the class Zoo with the constructor accepting animals. But the Zoo wants every animal to have a name and hence defines […]

Notify app when iPad date time settings changed

I would like to get notified when ipad‘s date-time settings is changed. Is there any way for that?. I am using NSDateFormatter to find whether iPad/iphone time mode is 12 or 24 hr format. NSDateFormatter is seems to take lots of time( seen in time profiling). So I would like to check use it only […]

How to make a UIScrollView snap to icons (like App Store: Feature)

What I want to get is the same behaviour that this scroll view has: I know that this is using HTML and not the native API, but I’m trying to implement it as a UIKit component. Now, to the behaviour I’m looking for: Notice that it’s a paged scroll view, but the “page size” is […]

How does incremental localization work?

I’m trying to build my first localized application. I have all the strings in code translated using NSLocalizedString (for use with genstrings tool). Now I’m bumping into ibtool. How does incremental localization work? Regarding to the manual page, I should write something like this: $ ibtool –previous-file path/to/prev.xib \ –incremental-file path/to/inc.xib –localize-incremental \ –write path/to/new.xib […]

How to securely include secret key/signature in iOS/Cocoa apps

I want to include a secret key into an iOS app so that the app can “prove” to a certain server that a request is coming from the app itself and not some other system. I know that simply hardcoding a secret key into the code itself is very vulnerable as anyone can jailbreak their […]

Core Data locks in background threads

I’m getting locks in Core Data. I really don’t understand the reason. Because I’m creating a background MOC when I’m processing in a background thread. Below you can see what a stack trace (I’m pausing the execution of the app) looks like when this happens: Thread 1, Queue : com.apple.main-thread #0 0x32d2a0fc in __psynch_mutexwait () […]

Transparent UILabel textColor on superview.superview (sort of)

I would like to achieve the same effect as in the new iTunes remote update for iOS 7 for my UILabel. If you look at this screen: (The one on the right) you’ll notice that the UILabel text color is the background blurred album cover without the black mask. At the moment I have transparent […]

Objective-C – Disadvantages to Bridging With C++?

So, I was bored today, and decide to mess with C++/Obj-C interpolation, and I found a way to create a very interesting setup. @protocol NSCPPObj <NSObject> -(id) init; -(id) initWithInt:(int) value; -(int) somethingThatReturnsAValue; -(void) doSomething; @end class NSCPPObj : objc_object { public: static Class cls(); int iVar; NSCPPObj(); NSCPPObj(int); int somethingThatReturnsAValue(); void doSomething(); }; As […]

NSRegularExpression validate email

i want to use the NSRegularExpression Class to validate if an NSString is an email address. Something like this pseudocode: – (BOOL)validateMail : (NSString *)email { NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:@”” options:NSRegularExpressionCaseInsensitive error:NULL]; if(emailValidated) { return YES; }else{ return NO; } } But i don’t know how exactly i validate an NSString if it’s looking […]

Navigating the Core Data Object Graph

I asked a question yesterday where I really should have started with a simpler example. Having distilled my question to the basics, I’ve managed to solve my problem using existing SO questions and answers. I’m summarising my question here (and providing my own solution) because I don’t think there are any posts that explain this […]