NSDate initWithString - objective-c

After updating Xcode to version 4.2 I received the following warning in my current project:
warning: 'NSDate' may not respond to 'initWithString:'
What must I do? :)

This method is in the documentation only noted at the Mac OSX page, not the iOS.
Why Apple has different versions is unclear to me, but they luckily respond the same.
Because the class reference for iOS says there is no such method for iOS NSDate, you get the warning.
Your code, however, will respond perfectly fine.
To silence the warning, you should indeed use NSDateFormatter.
Regards,
Jacco

You should use NSDateFormatter to get an NSDate object from a string. This will give you more flexibility with the format of the input string.
NSDateFormatter Reference

Read the changes at this website http://developer.apple.com/library/ios/#releasenotes/General/iOS42APIDiffs/index.html
Sometimes they change little syntax things and make newer and better ways of doing things.

Related

NSString method deprecated, but replacement not there?

I am (re)building a project written in objective c in XCode 3.2.6 64 bit under a 10.6.8 VM based on the 10.5 SDK (for compatibility with 10.5 and up - so this is a given.) The build is up and working. But. I'm trying to address the last four warnings in this project. They're all the same warning. Specifically...
In the project, there are four ASCII c strings that need to be converted to four corresponding instances of objective c's NSString. There are four essentially identical cases. This is how it's being done:
[tf setStringValue: [NSString stringWithCString: strg]]
This works, but results in (four) warnings that stringWithCString is deprecated and looking further, I find that's been true since about 10.4. So I'd expect the 10.5 SDK to have whatever replacement is required.
Looking at the docs, the suggested replacement is:
[tf setStringValue: [NSString stringWithCString:NSASCIIStringEncoding: strg]]
However, when this is used, XCode says:
'NSString' may not respond to '+stringWithCString::'
Which probably means it really won't respond. And besides, even if it does, replacing one warning with another.... yech.
Anyone know what I should be doing differently? I realize that this is old, old stuff, but surely Back In The Day people didn't just let these warnings clutter up their builds? Have I just got some kind of syntax error here, or... ?
[NSString stringWithCString:NSASCIIStringEncoding: strg]
The correct syntax for calling this method is:
[NSString stringWithCString:strg encoding:NSASCIIStringEncoding]

NSCoder Availability

trying to use the initwithcoder init method in my custom NSControl Class.
It works just fine and does what I need it to do. However and this leads me to asking this question on this here forum -> in the class reference of NCControl when you scroll down to initWithCoder and click on it it states SDKs
macOS 10.10+ which leads me to believe that it would not work and do what I need it to do on versions prior to that... Unless Apple's documentation once again is wrong...
BTW - from Apple's own reference (Online as well as offline) apparently the NSCoder Class is also suffering from this SDKs macOS 10.10+
https://developer.apple.com/reference/foundation/nscoder
The strange thing is that in the documentation describing how a NIB is loaded and which init methods it calls on various objects, it describes initWithCoder as being the designated initializer but that documentation is from before 10.10.
Thanks to anyone who can set my mind at ease ;-)
Yes it will not work before defined version. I think you are checking versions of Swift, if you select objective-c you should see version 10.0+ which i think should work fine for your need. If you change the language, you can put your mind to ease :)
I am assuming if you would like to support things that far back you are going to use objective-c over swift.
Check the below image for NSCoder documentation after you select objective-c on right hand side.

Is there a way to rewrite dealloc in Automated Reference Counting? Why doesn't it work?

I am a second year Computer Programming student who is working on a program in Objective C. (Xcode, if it matters). Right now, we are working on animation and moving animated objects across the screen. Right now, I am dealing with an error that is driving me insane. My program is using ARC, Automated Reference Counting, which supposedly is supposed to help with memory management. However, for some reason, I can't seem to use
[super dealloc];
It always gives me an error that says "ARC forbids explicit message send of 'dealloc'
Why is this? How do I fix it? It works in my other programs, just not this one?
Also, release doesn't seem to work either. For example, the following code gives me 2 errors:
[fireBall release];
The error says "'release' is unavailable: not available in automatic reference counting mode" and the next error says "ARC forbids explicit message send of 'release'." Why does this happen, how can I fix it? This code works in my other programs. Can someone please explain, or at least provide a link that can solve all my problems? Thanks for reading
You should take some time to fully go through Apple's Guide on ARC
It will save you tons of time and it's something definitely worth understanding.
You can define your own dealloc method, you just cant call [super dealloc] (ARC calls it automatically). The same is true for release, you dont need to call it as ARC handles placing it in your code
Simple, just remove that line. ARC takes care of all release/autorelease/dealloc calls.
ARC has 100% (pretty much) insight in the lifetime of your objects and inserts these calls for you.
You can still override the dealloc method to do some cleanup though.

Reset/fix Xcode 4.5 code completion

One of the new "features" in Xcode 4.5 was supposed to be vastly improved code completion. It was supposed to learn what you type regularly and provide these more frequently as options for code completion.
However, for me this isn't working at all.
One of the famously bad code completion words is NSString.
When I type it I get...
NS - NSAddedPersistentStoresKey
NSS - NSSaveChangesRequest
NSSt - NSStoreModelVersionHashesKey
NSStr - NSStream
NSStri - NSStrikethroughStyleAttributeName
NSStrin - NSString
I have never used any of the other suggestions given and most of them I'm not actually sure what they are. I use NSString many times a day, why wasn't it suggested first? In fact, apart from NSSet I don't think I've ever used another class that begins with NSS.
Also, when looking for NSLog() which used to get suggested when I typed NSL I now get...
NS - NSAddedPersistentStoresKey
NSL - NSLayoutAttribute
NSLo - NSLoadedClasses
NSLog - NSLog(<#id, ...#>)
Again, never heard of the others.
Is there any way to fix this so that I get the functionality that Apple says I should be getting?
Thanks for any help.
OK, I deleted the UserInfo folder from ~/Library/Developer/Xcode/ and it seems to have fixed it.

UIImage Category method is not calling iOS SDK

i have implemented UIImage Category...and i am trying to call a method from my viewcontroller..strangely i am getting below shown warning
can anyone please answer why i am getting this warning and how to avoid that
It looks like the compiler doesn't know if it needs to release the value returned by the selector. So I'm guessing you have ARC enabled, or maybe the compiler is checking this anyway as part of the static analysis stuff.
The selector may return a +1 retained object, or an autoreleased object. There is no way to know this at compile time so the compiler is giving you this warning.
Generally you should not get objects from selectors like this. The better solution would be with a strongly typed delegate interface where the memory semantics are clearer.