iOS5 ARC errors: SKPSMTPMessage - ios5

I'm attempting to incorporate this bit of code into a new(iOS 5) project... Problem is, I'm using ARC and it REALLY doesn't like the code as written.
I've been able to resolve most of the errors, but I'm stuck with 3 errors I can't seem to figure out.
Error #1:
Existing ivar 'delegate' for unsafe_unretained property 'delegate'
must be _unsafe_unretained
.h
#interface SKPSMTPMessage : NSObject {
NSOutputStream *outputStream;
NSInputStream *inputStream;
id <SKPSMTPMessageDelegate> delegate;
}
#property(nonatomic, assign) id <SKPSMTPMessageDelegate> delegate;
.m
#synthesize login, pass, relayHost, relayPorts, subject, fromEmail, toEmail, parts, requiresAuth, inputString, wantsSecure, \
delegate, connectTimer, connectTimeout, watchdogTimer, validateSSLChain;
Errors #2 & #3:
Passing address of non-local object to _autoreleasing parameter for
write-back
.h
#interface SKPSMTPMessage : NSObject {
NSOutputStream *outputStream;
NSInputStream *inputStream;
id <SKPSMTPMessageDelegate> delegate;
}
.m
[NSStream getStreamsToHostNamed:relayHost port:relayPort inputStream:&inputStream outputStream:&outputStream];
Any guidance will be greatly appreciated.
Thanks.

I have found right solution for this question.
The answer is: Dont bother yourself converting code manually.
You just need to add compiler flag -fno-objc-arc to imported classes

Error #1
Replase
#property(nonatomic, assign) id <SKPSMTPMessageDelegate> delegate;
To
#property(nonatomic, _unsafe_unretained) id <SKPSMTPMessageDelegate> delegate;
You can't use assign with ARC
Error #2,3
Try to not alloc and init outputStream and inputStream variables.
NSInputStream *inputStream;
NSOutputStream *outputStream;
[NSStream getStreamsToHostNamed:relayHost port:relayPort inputStream:&inputStream outputStream:&outputStream];

Related

existing instance variable delegate for property delegate with assign attribute must be unsafe_unretained

Getting error that on
#protocol TapDetectingImageViewDelegate;
#interface TapDetectingImageView : UIImageView {
id <TapDetectingImageViewDelegate> tapDelegate;
#property (nonatomic, assign) id <TapDetectingImageViewDelegate> tapDelegate;
#synthesize tapDelegate;
Tried everything like
_weak id <TapDetectingImageViewDelegate> tapDelegate;
#property (weak) id <TapDetectingImageViewDelegate> tapDelegate;
and even tried this also
_unsafe_unretained id <TapDetectingImageViewDelegate> tapDelegate;
#property (_unsafe_unretained) id <TapDetectingImageViewDelegate> tapDelegate;
even tried removing instance variable definition as synthesize takes care of it when using ARC mode.
But still nothing is working to remove this error.
If anyone can help me to solve this error.
Thanks.
I'm new to Obj-C, I found this solution https://stackoverflow.com/a/10080387/3867557
and your code should look like:
#protocol TapDetectingImageViewDelegate;
#interface TapDetectingImageView : UIImageView
#property (nonatomic, assign) id <TapDetectingImageViewDelegate> tapDelegate;
Hope it help.

arc with navigation delegate error property delegate not found on object of type viewcontroller

I'm hoping someone can shed some light on my question below.
I'm getting a property delegate not found on object of type viewcontroller error on when I declare the delegate in the parent view:
Here's the relevant code in the parent .h file:
#protocol ModalViewDelegate
- (void)didReceiveFrequencyMessage:(NSString *)message;
#end
#interface jhsManageRemindersViewController : UIViewController<UIAlertViewDelegate, UINavigationControllerDelegate, ModalViewDelegate>
and here's where I call the child view:
jhsScheduleViewController *jhsScheduleController = [[jhsScheduleViewController alloc]
initWithNibName:#"jhsScheduleViewControllerr" bundle:nil];
jhsScheduleController.delegate = self;
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:jhsScheduleController];
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:navigationController animated:YES];
and here's part of my child .h file
#protocol ModalViewDelegate ;
#interface jhsScheduleViewController : UIViewController {
//id<ModalViewDelegate> delegate;
// __unsafe_unretained id <ModalViewDelegate> _delegate;
__weak id <ModalViewDelegate> delegate;
NSMutableString *message;
}
#property ( weak) id<ModalViewDelegate> delegate;
//#property (nonatomic, weak) id<ModalViewDelegate> delegate;
#property (nonatomic, retain) NSMutableString *message;
and finally, here's my .m usage
#synthesize delegate;
//#synthesize delegate = _delegate;
I've viewed and tried various solutions based upon Stackoverflow questions and this recommended blogpost. I've included some of my attempted solutions in commented out code, just as an FYI.
I started with the code I had in an iOS4 app but that generates the error. As a footnote, this is an app with a TabBarController and a NavigationController
Can someone tell me how to fix this so the delegate error can be resolved?
Thank you for your help!
Well, I'm not sure what the problem was. But as a last resort, I saved every file, then tried to build it, with Xcode still reporting the error, which worked.
Actually, there was an error in the initWithNibName but it ran fine until it got to that point, and correcting the typo fixed that. Again, I'm not sure what the problem was but I seem to be on my way.

Cocos2d ,need to include protocol in my implementation file

So basically I have a protocol inside my interface that I need to include in my implementation because I am getting an incomplete error and therefore can't continue.
. h file
#interface waveLayer1 : CCLayer <GameKitHelperProtocol>
{
...
}
.m file
#implementation waveLayer1
GameKitHelper.h file
#import "cocos2d.h"
#import <GameKit/GameKit.h>
#protocol GameKitHelperProtocol
-(void) onLocalPlayerAuthenticationChanged;
-(void) onFriendListReceived: (NSArray*)friends;
-(void) onPlayerInfoReceived:(NSArray*)players;
#end
#interface GameKitHelper : NSObject {
id<GameKitHelperProtocol> delegate; bool isGameCenterAvailable; NSError* lastError;
}
#property (nonatomic, retain) id<GameKitHelperProtocol> delegate;
#property (nonatomic, readonly) bool isGameCenterAvailable; #property (nonatomic, readonly) NSError* lastError;
+(GameKitHelper*) sharedGameKitHelper;
// Player authentication, info
-(void) authenticateLocalPlayer;
-(void) getLocalPlayerFriends;
-(void) getPlayerInfo:(NSArray*)players;
#end
The error is "Method in protocol not implemented" I have more files I can show ,but to save room I decided to see if you can help me fix this with just these codes
#interface waveLayer1 : CCLayer <GameKitHelperProtocol>
This says that "wavelayer1" implements the protocol "GameKitHelperProtocol".
Method in protocol not implemented
says that a method declared in a protocol has not been implemented. Chances are that you forgot to implement one of the "GameKitHelperProtocol" methods, which makes your class NOT implement that protocol, which violates the declaration you made, which causes the compiler to output an error.
Implement these 3 methods in your waveLayer1 class..
-(void) onLocalPlayerAuthenticationChanged;
-(void) onFriendListReceived:(NSArray*)friends;
-(void) onPlayerInfoReceived:(NSArray*)players;
When you declare that a class adopts a protocol, you must write an implementation for all required methods that are defined in that protocol. So in this case, you need to add method implementations that are defined in GameKitHelperProtocol.

No known instance method for selector error in NSMutableArray

I have a problem accessing a object in my array. I store "Place" objects in my NSMutableArray. I want to access this array for my TableView. I get the "No known instance method for selector" error in line one. See lines below.
cell.imageView = [[self.currentPlaces objectAtIndex:indexPath.row]picture];
cell.subtitleLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]description];
cell.objectNameLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]name];
This is my Place object:
#interface Place : NSObject{
CLLocation *objectLocation;
UIImageView *picture;
NSString *name;
NSString *description;
}
The access of the properties "description" and "name" is no problem. I just dont know why this error occurs.
Thx. Dominik
I had the same problem; what worked for me was passing the UIImage instead of the UIImageView. So your code should look like this:
#interface Place : NSObject{
CLLocation *objectLocation;
UIImage *picture;
NSString *name;
NSString *description;
}
and this
cell.imageView.image = [[self.currentPlaces objectAtIndex:indexPath.row]picture];
cell.subtitleLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]description];
cell.objectNameLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]name];
If that doesn't work I'll post some more code for you to look at.
You haven't actually declared any methods. What you have declared are instance variables. You should probably be using #propertys instead.
#interface Place : NSObject
#property (nonatomic, retain) CLLocation *objectLocation;
#property (nonatomic, retain) UIImageView *picture;
#property (nonatomic, copy) NSString *name;
#property (nonatomic, copy, getter=objectDescription) NSString *description;
#end
This will actually create the methods that you want. Note that I changed the method for the description property to read -objectDescription. This is because NSObject already declares the -description method and you shouldn't be overriding it with an unrelated property.
If you're on recent Clang, then this is all you need, and instance variables will get synthesized automatically (using an underbar prefix, e.g. _picture). If you're on an older version (e.g. if this causes errors), you need to add #synthesize lines, as in
#implementation Place
#synthesize objectLocation=_objectLocation;
#synthesize picture=_picture;
#synthesize name=_name;
#synthesize description=_description;
#end

Error when declaring NSManagedObjectContext

I'm trying to create a NSManagedObjectContext object. They error reads as follows:
Expected specifier-qualifier-list
before 'NSManagedObjectContext'
and here is my header file:
#import <UIKit/UIKit.h>
#interface FavouritesViewController : UITableViewController {
NSArray *favourites;
NSManagedObjectContext *context;
}
#property (nonatomic, retain) NSArray *favourites;
#property (nonatomic, retain) NSManagedObjectContext *context;
#end
Anyone know I might be missing here?
Most probably you have forgotten to include the CoreData header in your file. Right after the line #import <UIKit/UIKit.h> you need another line that reads #import <CoreData/CoreData.h>. After this the file should compile fine. Also make sure that you have CoreData in your linked libraries, otherwise you will get runtime errors.
You need to add #class NSManagedObject above your interface directive. This will tell the compiler that NSManagedObject is a real class. You then need to have #import <CoreData/CoreData.h> in your .m file.