anyobject Questions

5

Solved

How could we convert anyobject to string in swift 3, it's very easy in the older version by using. var str = toString(AnyObject) I tried String(AnyObject) but the output is always optional, even...
Willpower asked 14/10, 2016 at 13:34

3

I have a generic struct declared as follows: struct WeakReference<T: AnyObject> { weak var value: T? init(value: T?) { self.value = value } } And a protocol: protocol SomeProtocol: c...
Cult asked 6/8, 2018 at 11:38

3

Solved

Hello StackOverflow :) I've been running into a weird problem since I upgraded to swift 2.0 I'm trying to set a border color, so I'm writing self.layer.borderColor = borderColor as! CGColor where...
Mirisola asked 7/11, 2015 at 23:52

1

I read swift documentation in apple site. There is a function swapTwoValues, which swaps two any given values func swapTwoValues1<T>(_ a: inout T, _ b: inout T) { let temporaryA = a a = b ...
Cathode asked 26/7, 2017 at 8:43

1

Solved

let json = [ "left" : 18, "deadline" : "May 10", "progress" : 0.6 ] as [String: AnyObject] let ss = json["progress"] as? Float let sss = json["progress"] as? Double print("ss = \(ss)\n sss = \(...
Lorin asked 26/4, 2017 at 1:31

2

Solved

I created an extension on 'Dictionary' to help me parse JSON. The method below helps me do this: func toJSONString() -> String? { if let dict = self as? AnyObject { if let data = try? JSONSer...
Hengel asked 30/9, 2016 at 20:18

3

Solved

I want to get Addresses from profile dictionary,but I got the error "type any? has no subscript members" var address:[[String : Any]] = [["Address": "someLocation", "City": "ABC","Zip" : 123],["Ad...
Disincentive asked 15/8, 2016 at 14:13

2

Solved

there are two situation make me confuse when develop swift 2.2 by using Xcode 7.1, please see the example below, thanks First, when import Foundation, I declared an testArray which contains two i...
Dharma asked 4/5, 2016 at 9:46

4

Solved

This question was inspired by mz2's answer on the question Check for object type fails with "is not a type" error. Consider an empty Swift class: class MyClass { } Attempting to call ...
Arella asked 25/4, 2016 at 22:0

2

In Swift, how is it that AnyObject supports subscripts, even for types that are't subscriptable? Example: let numbers: AnyObject = [11, 22, 33] numbers[0] // returns 11 let prices: AnyObject = ["...
Zoba asked 21/1, 2016 at 22:26

2

Solved

In Java you can some times use generics without caring about the actual type. Can you do that in Swift? For instance MyClass<AnyObject> doesn't work like MyClass<?> would in Java. At I...
Barretter asked 20/11, 2015 at 16:24

4

Solved

I would like to create a method like this for my projects: func print(obj: AnyObject) { if let rect = obj as? CGRect { println(NSStringFromCGRect(rect)) } else if let size = obj as? CGSize { ...
Dartboard asked 1/4, 2015 at 13:18

1

Solved

I'm trying to mark a variable of a generic type as weak: class X<T> { weak var t: T? } If I don't put in any constraints for T I get the error weak cannot be applied to non-class type 'T'...
Southwestwards asked 5/3, 2015 at 18:16
1

© 2022 - 2024 — McMap. All rights reserved.