whats the equivalent of java's instanceof in Swift?
Just like java's instanceOf keyword whats the equivalent in Swift?
java example:
A a = new A();
boolean isInstanceOfA = a instanceof A;
Here isInstanceOfA is true
So i need something similar in Swift
ios swift
add a comment |
Just like java's instanceOf keyword whats the equivalent in Swift?
java example:
A a = new A();
boolean isInstanceOfA = a instanceof A;
Here isInstanceOfA is true
So i need something similar in Swift
ios swift
2
try operator "is": a is A
– nerowolfe
Jun 1 '16 at 8:30
nevermind I found the answer in one of stackoverflow chat rooms
– Bhargav
Jun 1 '16 at 8:31
or maybe I should delete this question if its already answer, a link to a similarly asked question would be good.
– Bhargav
Jun 1 '16 at 8:32
1
You can useis
operator An example can be found here: stackoverflow.com/a/36900103/4791032
– Bogdan Ustyak
Jun 1 '16 at 8:32
add a comment |
Just like java's instanceOf keyword whats the equivalent in Swift?
java example:
A a = new A();
boolean isInstanceOfA = a instanceof A;
Here isInstanceOfA is true
So i need something similar in Swift
ios swift
Just like java's instanceOf keyword whats the equivalent in Swift?
java example:
A a = new A();
boolean isInstanceOfA = a instanceof A;
Here isInstanceOfA is true
So i need something similar in Swift
ios swift
ios swift
asked Jun 1 '16 at 8:28


BhargavBhargav
5,41912551
5,41912551
2
try operator "is": a is A
– nerowolfe
Jun 1 '16 at 8:30
nevermind I found the answer in one of stackoverflow chat rooms
– Bhargav
Jun 1 '16 at 8:31
or maybe I should delete this question if its already answer, a link to a similarly asked question would be good.
– Bhargav
Jun 1 '16 at 8:32
1
You can useis
operator An example can be found here: stackoverflow.com/a/36900103/4791032
– Bogdan Ustyak
Jun 1 '16 at 8:32
add a comment |
2
try operator "is": a is A
– nerowolfe
Jun 1 '16 at 8:30
nevermind I found the answer in one of stackoverflow chat rooms
– Bhargav
Jun 1 '16 at 8:31
or maybe I should delete this question if its already answer, a link to a similarly asked question would be good.
– Bhargav
Jun 1 '16 at 8:32
1
You can useis
operator An example can be found here: stackoverflow.com/a/36900103/4791032
– Bogdan Ustyak
Jun 1 '16 at 8:32
2
2
try operator "is": a is A
– nerowolfe
Jun 1 '16 at 8:30
try operator "is": a is A
– nerowolfe
Jun 1 '16 at 8:30
nevermind I found the answer in one of stackoverflow chat rooms
– Bhargav
Jun 1 '16 at 8:31
nevermind I found the answer in one of stackoverflow chat rooms
– Bhargav
Jun 1 '16 at 8:31
or maybe I should delete this question if its already answer, a link to a similarly asked question would be good.
– Bhargav
Jun 1 '16 at 8:32
or maybe I should delete this question if its already answer, a link to a similarly asked question would be good.
– Bhargav
Jun 1 '16 at 8:32
1
1
You can use
is
operator An example can be found here: stackoverflow.com/a/36900103/4791032– Bogdan Ustyak
Jun 1 '16 at 8:32
You can use
is
operator An example can be found here: stackoverflow.com/a/36900103/4791032– Bogdan Ustyak
Jun 1 '16 at 8:32
add a comment |
5 Answers
5
active
oldest
votes
isKindOfClass()
method, from NSObjectProtocol is the equivalent of java's instanceof keyword, in java it's a keyword but in swift it's a protocol method, but they behave similarly and are used in similar contexts.
isKindOfClass:
returns YES if the receiver is an instance of the
specified class or an instance of any class that inherits from the
specified class.
Which is exactly what instanceof keyword does in Java related link
Example:
let a: A = A()
let isInstanceOfA: Bool = a.isKindOfClass(A) // returns true.
Also you can use the is
keyword
let a: A = A()
let isInstanceOfA: Bool = a is A
The difference:
is
works with any class in Swift, whereasisKindOfClass()
works only with those classes that are subclasses ofNSObject
or otherwise implementNSObjectProtocol
.is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
So no is
keyword doesn't work like instanceof
1
AFAIK there aren't any cases where isKindOfClass is required. I would strongly suggest the answer is amended to make clear thatis
would be the preferred usage.
– PeejWeej
Sep 1 '17 at 21:58
@PEEJWEEJ the intention here is to provide all available options and what exactly it does thereby giving a "Complete" answer.
– Bhargav
Sep 4 '17 at 4:13
1
Yeah and that's fine, but given that it's Objective-C and not Swift and thus will be unavailable on any platform not including the Objective-C runtime, isKindOfClass is a platform specific alternative, not the Swift equivalent.
– PeejWeej
Sep 4 '17 at 17:39
add a comment |
let a = A()
let isInstanceOfA = a is A
is keyword works like instanceof?
– Bhargav
Jun 1 '16 at 8:45
yes, same as instanceof
– ZHZ
Jun 1 '16 at 8:57
ill give it a try
– Bhargav
Jun 1 '16 at 9:06
then this begs the question whats the difference betweenisKindOfClass
method andis
keyword
– Bhargav
Jun 1 '16 at 9:25
1
is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
– Bhargav
Jun 1 '16 at 9:53
add a comment |
For swift3 and swift4 it's:
if someInstance is SomeClass {
...
}
if your class is extending NSObject
you can also use:
if someInstance.isKind(of: SomeClass.self) {
...
}
This is actually valid from Swift 1.0
– Sulthan
Nov 22 '18 at 15:34
add a comment |
For Swift 4.x it's:
func getOrElse<T>(defaultVal:T) -> T {
if let selfVal = self, selfVal is T {
return selfVal as! T
} else {
return defaultVal
}
}
Very short variant(by suggestion @Sulthan):
extension Optional {
func getOrElse<T>(defaultVal:T) -> T {
return (self as? T) ?? defaultVal
}
}
1
You know that this would be easier to implement using(self as? T) ?? defaultVal
?
– Sulthan
Nov 22 '18 at 15:35
Unlike Java, in Swift optionals are a native type and there are language operators that work with them. Thats why you rarely have to define new methods on Optional - the necessary funcionality is already there.
– Sulthan
Nov 23 '18 at 6:53
add a comment |
With objective-c it's isKindOfClass:[ClassName class]
.
With swift it's isKindOfClass(Classname.class())
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37563319%2fwhats-the-equivalent-of-javas-instanceof-in-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
isKindOfClass()
method, from NSObjectProtocol is the equivalent of java's instanceof keyword, in java it's a keyword but in swift it's a protocol method, but they behave similarly and are used in similar contexts.
isKindOfClass:
returns YES if the receiver is an instance of the
specified class or an instance of any class that inherits from the
specified class.
Which is exactly what instanceof keyword does in Java related link
Example:
let a: A = A()
let isInstanceOfA: Bool = a.isKindOfClass(A) // returns true.
Also you can use the is
keyword
let a: A = A()
let isInstanceOfA: Bool = a is A
The difference:
is
works with any class in Swift, whereasisKindOfClass()
works only with those classes that are subclasses ofNSObject
or otherwise implementNSObjectProtocol
.is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
So no is
keyword doesn't work like instanceof
1
AFAIK there aren't any cases where isKindOfClass is required. I would strongly suggest the answer is amended to make clear thatis
would be the preferred usage.
– PeejWeej
Sep 1 '17 at 21:58
@PEEJWEEJ the intention here is to provide all available options and what exactly it does thereby giving a "Complete" answer.
– Bhargav
Sep 4 '17 at 4:13
1
Yeah and that's fine, but given that it's Objective-C and not Swift and thus will be unavailable on any platform not including the Objective-C runtime, isKindOfClass is a platform specific alternative, not the Swift equivalent.
– PeejWeej
Sep 4 '17 at 17:39
add a comment |
isKindOfClass()
method, from NSObjectProtocol is the equivalent of java's instanceof keyword, in java it's a keyword but in swift it's a protocol method, but they behave similarly and are used in similar contexts.
isKindOfClass:
returns YES if the receiver is an instance of the
specified class or an instance of any class that inherits from the
specified class.
Which is exactly what instanceof keyword does in Java related link
Example:
let a: A = A()
let isInstanceOfA: Bool = a.isKindOfClass(A) // returns true.
Also you can use the is
keyword
let a: A = A()
let isInstanceOfA: Bool = a is A
The difference:
is
works with any class in Swift, whereasisKindOfClass()
works only with those classes that are subclasses ofNSObject
or otherwise implementNSObjectProtocol
.is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
So no is
keyword doesn't work like instanceof
1
AFAIK there aren't any cases where isKindOfClass is required. I would strongly suggest the answer is amended to make clear thatis
would be the preferred usage.
– PeejWeej
Sep 1 '17 at 21:58
@PEEJWEEJ the intention here is to provide all available options and what exactly it does thereby giving a "Complete" answer.
– Bhargav
Sep 4 '17 at 4:13
1
Yeah and that's fine, but given that it's Objective-C and not Swift and thus will be unavailable on any platform not including the Objective-C runtime, isKindOfClass is a platform specific alternative, not the Swift equivalent.
– PeejWeej
Sep 4 '17 at 17:39
add a comment |
isKindOfClass()
method, from NSObjectProtocol is the equivalent of java's instanceof keyword, in java it's a keyword but in swift it's a protocol method, but they behave similarly and are used in similar contexts.
isKindOfClass:
returns YES if the receiver is an instance of the
specified class or an instance of any class that inherits from the
specified class.
Which is exactly what instanceof keyword does in Java related link
Example:
let a: A = A()
let isInstanceOfA: Bool = a.isKindOfClass(A) // returns true.
Also you can use the is
keyword
let a: A = A()
let isInstanceOfA: Bool = a is A
The difference:
is
works with any class in Swift, whereasisKindOfClass()
works only with those classes that are subclasses ofNSObject
or otherwise implementNSObjectProtocol
.is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
So no is
keyword doesn't work like instanceof
isKindOfClass()
method, from NSObjectProtocol is the equivalent of java's instanceof keyword, in java it's a keyword but in swift it's a protocol method, but they behave similarly and are used in similar contexts.
isKindOfClass:
returns YES if the receiver is an instance of the
specified class or an instance of any class that inherits from the
specified class.
Which is exactly what instanceof keyword does in Java related link
Example:
let a: A = A()
let isInstanceOfA: Bool = a.isKindOfClass(A) // returns true.
Also you can use the is
keyword
let a: A = A()
let isInstanceOfA: Bool = a is A
The difference:
is
works with any class in Swift, whereasisKindOfClass()
works only with those classes that are subclasses ofNSObject
or otherwise implementNSObjectProtocol
.is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
So no is
keyword doesn't work like instanceof
edited Jun 1 '16 at 9:53
answered Jun 1 '16 at 8:30


BhargavBhargav
5,41912551
5,41912551
1
AFAIK there aren't any cases where isKindOfClass is required. I would strongly suggest the answer is amended to make clear thatis
would be the preferred usage.
– PeejWeej
Sep 1 '17 at 21:58
@PEEJWEEJ the intention here is to provide all available options and what exactly it does thereby giving a "Complete" answer.
– Bhargav
Sep 4 '17 at 4:13
1
Yeah and that's fine, but given that it's Objective-C and not Swift and thus will be unavailable on any platform not including the Objective-C runtime, isKindOfClass is a platform specific alternative, not the Swift equivalent.
– PeejWeej
Sep 4 '17 at 17:39
add a comment |
1
AFAIK there aren't any cases where isKindOfClass is required. I would strongly suggest the answer is amended to make clear thatis
would be the preferred usage.
– PeejWeej
Sep 1 '17 at 21:58
@PEEJWEEJ the intention here is to provide all available options and what exactly it does thereby giving a "Complete" answer.
– Bhargav
Sep 4 '17 at 4:13
1
Yeah and that's fine, but given that it's Objective-C and not Swift and thus will be unavailable on any platform not including the Objective-C runtime, isKindOfClass is a platform specific alternative, not the Swift equivalent.
– PeejWeej
Sep 4 '17 at 17:39
1
1
AFAIK there aren't any cases where isKindOfClass is required. I would strongly suggest the answer is amended to make clear that
is
would be the preferred usage.– PeejWeej
Sep 1 '17 at 21:58
AFAIK there aren't any cases where isKindOfClass is required. I would strongly suggest the answer is amended to make clear that
is
would be the preferred usage.– PeejWeej
Sep 1 '17 at 21:58
@PEEJWEEJ the intention here is to provide all available options and what exactly it does thereby giving a "Complete" answer.
– Bhargav
Sep 4 '17 at 4:13
@PEEJWEEJ the intention here is to provide all available options and what exactly it does thereby giving a "Complete" answer.
– Bhargav
Sep 4 '17 at 4:13
1
1
Yeah and that's fine, but given that it's Objective-C and not Swift and thus will be unavailable on any platform not including the Objective-C runtime, isKindOfClass is a platform specific alternative, not the Swift equivalent.
– PeejWeej
Sep 4 '17 at 17:39
Yeah and that's fine, but given that it's Objective-C and not Swift and thus will be unavailable on any platform not including the Objective-C runtime, isKindOfClass is a platform specific alternative, not the Swift equivalent.
– PeejWeej
Sep 4 '17 at 17:39
add a comment |
let a = A()
let isInstanceOfA = a is A
is keyword works like instanceof?
– Bhargav
Jun 1 '16 at 8:45
yes, same as instanceof
– ZHZ
Jun 1 '16 at 8:57
ill give it a try
– Bhargav
Jun 1 '16 at 9:06
then this begs the question whats the difference betweenisKindOfClass
method andis
keyword
– Bhargav
Jun 1 '16 at 9:25
1
is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
– Bhargav
Jun 1 '16 at 9:53
add a comment |
let a = A()
let isInstanceOfA = a is A
is keyword works like instanceof?
– Bhargav
Jun 1 '16 at 8:45
yes, same as instanceof
– ZHZ
Jun 1 '16 at 8:57
ill give it a try
– Bhargav
Jun 1 '16 at 9:06
then this begs the question whats the difference betweenisKindOfClass
method andis
keyword
– Bhargav
Jun 1 '16 at 9:25
1
is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
– Bhargav
Jun 1 '16 at 9:53
add a comment |
let a = A()
let isInstanceOfA = a is A
let a = A()
let isInstanceOfA = a is A
answered Jun 1 '16 at 8:38
ZHZZHZ
1,570715
1,570715
is keyword works like instanceof?
– Bhargav
Jun 1 '16 at 8:45
yes, same as instanceof
– ZHZ
Jun 1 '16 at 8:57
ill give it a try
– Bhargav
Jun 1 '16 at 9:06
then this begs the question whats the difference betweenisKindOfClass
method andis
keyword
– Bhargav
Jun 1 '16 at 9:25
1
is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
– Bhargav
Jun 1 '16 at 9:53
add a comment |
is keyword works like instanceof?
– Bhargav
Jun 1 '16 at 8:45
yes, same as instanceof
– ZHZ
Jun 1 '16 at 8:57
ill give it a try
– Bhargav
Jun 1 '16 at 9:06
then this begs the question whats the difference betweenisKindOfClass
method andis
keyword
– Bhargav
Jun 1 '16 at 9:25
1
is
takes a type that must be hard-coded at compile-time.isKindOfClass:
takes an expression whose value can be computed at runtime.
– Bhargav
Jun 1 '16 at 9:53
is keyword works like instanceof?
– Bhargav
Jun 1 '16 at 8:45
is keyword works like instanceof?
– Bhargav
Jun 1 '16 at 8:45
yes, same as instanceof
– ZHZ
Jun 1 '16 at 8:57
yes, same as instanceof
– ZHZ
Jun 1 '16 at 8:57
ill give it a try
– Bhargav
Jun 1 '16 at 9:06
ill give it a try
– Bhargav
Jun 1 '16 at 9:06
then this begs the question whats the difference between
isKindOfClass
method and is
keyword– Bhargav
Jun 1 '16 at 9:25
then this begs the question whats the difference between
isKindOfClass
method and is
keyword– Bhargav
Jun 1 '16 at 9:25
1
1
is
takes a type that must be hard-coded at compile-time. isKindOfClass:
takes an expression whose value can be computed at runtime.– Bhargav
Jun 1 '16 at 9:53
is
takes a type that must be hard-coded at compile-time. isKindOfClass:
takes an expression whose value can be computed at runtime.– Bhargav
Jun 1 '16 at 9:53
add a comment |
For swift3 and swift4 it's:
if someInstance is SomeClass {
...
}
if your class is extending NSObject
you can also use:
if someInstance.isKind(of: SomeClass.self) {
...
}
This is actually valid from Swift 1.0
– Sulthan
Nov 22 '18 at 15:34
add a comment |
For swift3 and swift4 it's:
if someInstance is SomeClass {
...
}
if your class is extending NSObject
you can also use:
if someInstance.isKind(of: SomeClass.self) {
...
}
This is actually valid from Swift 1.0
– Sulthan
Nov 22 '18 at 15:34
add a comment |
For swift3 and swift4 it's:
if someInstance is SomeClass {
...
}
if your class is extending NSObject
you can also use:
if someInstance.isKind(of: SomeClass.self) {
...
}
For swift3 and swift4 it's:
if someInstance is SomeClass {
...
}
if your class is extending NSObject
you can also use:
if someInstance.isKind(of: SomeClass.self) {
...
}
edited Nov 22 '18 at 15:26


Mariusz Wiazowski
508513
508513
answered Aug 7 '17 at 15:35
algridalgrid
2,28121014
2,28121014
This is actually valid from Swift 1.0
– Sulthan
Nov 22 '18 at 15:34
add a comment |
This is actually valid from Swift 1.0
– Sulthan
Nov 22 '18 at 15:34
This is actually valid from Swift 1.0
– Sulthan
Nov 22 '18 at 15:34
This is actually valid from Swift 1.0
– Sulthan
Nov 22 '18 at 15:34
add a comment |
For Swift 4.x it's:
func getOrElse<T>(defaultVal:T) -> T {
if let selfVal = self, selfVal is T {
return selfVal as! T
} else {
return defaultVal
}
}
Very short variant(by suggestion @Sulthan):
extension Optional {
func getOrElse<T>(defaultVal:T) -> T {
return (self as? T) ?? defaultVal
}
}
1
You know that this would be easier to implement using(self as? T) ?? defaultVal
?
– Sulthan
Nov 22 '18 at 15:35
Unlike Java, in Swift optionals are a native type and there are language operators that work with them. Thats why you rarely have to define new methods on Optional - the necessary funcionality is already there.
– Sulthan
Nov 23 '18 at 6:53
add a comment |
For Swift 4.x it's:
func getOrElse<T>(defaultVal:T) -> T {
if let selfVal = self, selfVal is T {
return selfVal as! T
} else {
return defaultVal
}
}
Very short variant(by suggestion @Sulthan):
extension Optional {
func getOrElse<T>(defaultVal:T) -> T {
return (self as? T) ?? defaultVal
}
}
1
You know that this would be easier to implement using(self as? T) ?? defaultVal
?
– Sulthan
Nov 22 '18 at 15:35
Unlike Java, in Swift optionals are a native type and there are language operators that work with them. Thats why you rarely have to define new methods on Optional - the necessary funcionality is already there.
– Sulthan
Nov 23 '18 at 6:53
add a comment |
For Swift 4.x it's:
func getOrElse<T>(defaultVal:T) -> T {
if let selfVal = self, selfVal is T {
return selfVal as! T
} else {
return defaultVal
}
}
Very short variant(by suggestion @Sulthan):
extension Optional {
func getOrElse<T>(defaultVal:T) -> T {
return (self as? T) ?? defaultVal
}
}
For Swift 4.x it's:
func getOrElse<T>(defaultVal:T) -> T {
if let selfVal = self, selfVal is T {
return selfVal as! T
} else {
return defaultVal
}
}
Very short variant(by suggestion @Sulthan):
extension Optional {
func getOrElse<T>(defaultVal:T) -> T {
return (self as? T) ?? defaultVal
}
}
edited Nov 23 '18 at 6:47
answered Nov 20 '18 at 6:36
mr.boyfoxmr.boyfox
9,18054361
9,18054361
1
You know that this would be easier to implement using(self as? T) ?? defaultVal
?
– Sulthan
Nov 22 '18 at 15:35
Unlike Java, in Swift optionals are a native type and there are language operators that work with them. Thats why you rarely have to define new methods on Optional - the necessary funcionality is already there.
– Sulthan
Nov 23 '18 at 6:53
add a comment |
1
You know that this would be easier to implement using(self as? T) ?? defaultVal
?
– Sulthan
Nov 22 '18 at 15:35
Unlike Java, in Swift optionals are a native type and there are language operators that work with them. Thats why you rarely have to define new methods on Optional - the necessary funcionality is already there.
– Sulthan
Nov 23 '18 at 6:53
1
1
You know that this would be easier to implement using
(self as? T) ?? defaultVal
?– Sulthan
Nov 22 '18 at 15:35
You know that this would be easier to implement using
(self as? T) ?? defaultVal
?– Sulthan
Nov 22 '18 at 15:35
Unlike Java, in Swift optionals are a native type and there are language operators that work with them. Thats why you rarely have to define new methods on Optional - the necessary funcionality is already there.
– Sulthan
Nov 23 '18 at 6:53
Unlike Java, in Swift optionals are a native type and there are language operators that work with them. Thats why you rarely have to define new methods on Optional - the necessary funcionality is already there.
– Sulthan
Nov 23 '18 at 6:53
add a comment |
With objective-c it's isKindOfClass:[ClassName class]
.
With swift it's isKindOfClass(Classname.class())
.
add a comment |
With objective-c it's isKindOfClass:[ClassName class]
.
With swift it's isKindOfClass(Classname.class())
.
add a comment |
With objective-c it's isKindOfClass:[ClassName class]
.
With swift it's isKindOfClass(Classname.class())
.
With objective-c it's isKindOfClass:[ClassName class]
.
With swift it's isKindOfClass(Classname.class())
.
edited Jun 1 '16 at 9:08


Aleksander Azizi
7,60665484
7,60665484
answered Jun 1 '16 at 8:39


PushkrajPushkraj
1,6751525
1,6751525
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37563319%2fwhats-the-equivalent-of-javas-instanceof-in-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
try operator "is": a is A
– nerowolfe
Jun 1 '16 at 8:30
nevermind I found the answer in one of stackoverflow chat rooms
– Bhargav
Jun 1 '16 at 8:31
or maybe I should delete this question if its already answer, a link to a similarly asked question would be good.
– Bhargav
Jun 1 '16 at 8:32
1
You can use
is
operator An example can be found here: stackoverflow.com/a/36900103/4791032– Bogdan Ustyak
Jun 1 '16 at 8:32