13

How does swift handle multiple options when animating UIView? I tried

UIView.animateWithDuration(0.2, delay: 0.0, options: .Repeat | .Autoreverse, animations: {self.alpha = 0.0}, completion: nil)

but seems to confuse the | with a bitwise operator:

Undefined symbols for architecture i386:
 "__TFSsoi1oUSs17_RawOptionSetType_USs21BitwiseOperationsTypeSs9Equatable__FTQ_Q__Q_", referenced from:
      __TFC17TextDrawing10cursorViewW8blinkingSb in cursorView.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am using the latest Xcode version from the AppStore.

Hristo
  • 6,382
  • 4
  • 24
  • 38
  • 1
    Seems that there is no problems with code. Have you tried deleted derived data for the project and cleaning the build? – Kirsteins Oct 07 '14 at 07:52
  • I cleaned the build (Product -> Clean) and deleted the derived data. It still gives the very same error. – Hristo Oct 07 '14 at 08:10
  • 1
    Try a clean build folder too: Project -> (hold down Alt key) -> Clean Build Folder – zisoft Oct 07 '14 at 08:43
  • Could you just double-check the exact build version number of Xcode you've got there for us, please? (Xcode menu/About Xcode) And can you reproduce the problem in a new, minimal project? (I agree with the others: I'm using | to combine UIViewAnimationOptions values just fine...) I'm wondering if there's something else in the code/build settings that's confusing the compiler/linker... – Matt Gibson Oct 07 '14 at 12:01
  • Also, it looks like you're building for the simulator (i.e. i386)—do you get the same problem building for a real device? – Matt Gibson Oct 07 '14 at 12:05
  • Put the class into another project, compiles just fine. The project where it belongs was created in the early xcode6 beta versions. I'll see what's different w/ the build settings – Hristo Oct 07 '14 at 17:24
  • @MattGibson - It doesn't build for a device either. – Hristo Oct 07 '14 at 17:49

5 Answers5

34

Swift 2:

UIView.animateWithDuration(0.2, delay: 0.0, options: [.Repeat, .Autoreverse], animations: {self.alpha = 0.0}, completion: nil)

Swift 3, 4, 5

UIView.animate(withDuration: 0.2, delay: 0.0, options: [.repeat, .autoreverse], animations: {self.alpha = 0.0}, completion: nil)
Karen Hovhannisyan
  • 1,140
  • 2
  • 21
  • 31
mxcl
  • 26,392
  • 12
  • 99
  • 98
2

The preview answer won't work in nowdays swift. The good answer was given by @mxcl.

If despite all you want to use this form, you have to retrieve the rawValue and rebuild a new UIViewAnimationOptions with an inclusive OR mask.

UIViewAnimationOptions(rawValue:(UIViewAnimationOptions.Autoreverse.rawvalue | UIViewAnimationOptions.Repeat.rawValue))
jcnm
  • 83
  • 1
  • 6
1

Swift 3: Tested and ok:

UIView.animate(withDuration: 0.2, delay: 0.0, options: [.repeat, .autoreverse], animations: {
            }, completion: nil)
Franck
  • 8,939
  • 8
  • 39
  • 57
0

From the docs it looks like what you are doing is correct?

Have you tried wrapping the options in parentheses?

Either that or put the options into a variable first and try that?

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
-1

This is working code for me:

        UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.Autoreverse | UIViewAnimationOptions.Repeat, animations: { () -> Void in
            disc.layer.transform = CATransform3DMakeScale(1.0, 1.0, 1.0)
            }) { (success) -> Void in
        }
Joachim Bøggild
  • 2,182
  • 1
  • 10
  • 4