0

I have something like

@property(nonatomic,retain) UIImageView *whiteBfFillUp;
@end

@synthesize locationManager;

I am new to swift coding. Can anyone tell me the equivalent code in swift.

user2842237
  • 57
  • 10
  • 1
    What are your learning resources for Objective-C? They seem to be outdated, as `@synthesize` is not needed since about 2012. Also `strong` should be used instead of `retain`. – Michał Ciuba Jun 10 '15 at 07:01
  • 1
    var whiteBfFillUp: UIImageView? – Volodymyr Jun 10 '15 at 07:01
  • Yeah this is not Modern Objective-c. Now-a-days `@synthesize` is done automatically for you. but The swift equivalent of that would be what @Vladimir S said. – cream-corn Jun 10 '15 at 07:02
  • This piece of code was written long ago.Anyway thanks for your response. – user2842237 Jun 10 '15 at 07:08
  • Possible duplicate of [@property/@synthesize equivalent in swift](http://stackoverflow.com/questions/24014800/property-synthesize-equivalent-in-swift) – byJeevan Apr 27 '16 at 06:16

2 Answers2

3

There is no equivalent.
In Swift when you write a varor let in a class or struct declaration you already declaring a property.

Define properties to store values

This is what is written in Swift documentation. If you are concerned about access control you can use private or public modifiers.

public var somePublicVariable = 0

If you'd like to override properties such as you did in Objective-C you will find useful properties observers such as didSet{} willSet{}.
If you need a a readonly properties you can make the setter private.

public private(set) var hours = 0
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Andrea
  • 26,120
  • 10
  • 85
  • 131
1

If you are only looking for equivalent of property, then you just need to create your class level variables. All class level variables are by default 'strong' or 'retain'. If, however, you want them to be weak then use weak.

This would be something like

var whiteBfFillUp: UIImageView? = nil

The ? at the end means that this is an optional type. If it's not, you would need to assign it some value in the init method, or right there.

Shamas S
  • 7,507
  • 10
  • 46
  • 58