Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 38 additions & 50 deletions ObjectiveKit/ObjectiveClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,79 +28,67 @@ public class ObjectiveClass <T: NSObject>: ObjectiveKitRuntimeModification {
///
/// - Returns: An array of instance variables.
public var ivars: [String] {
get {
var count: CUnsignedInt = 0
var ivars = [String]()
let ivarList = class_copyIvarList(internalClass, &count)
for i in (0..<Int(count)) {
let unwrapped = ivarList?[i].unsafelyUnwrapped
if let ivar = ivar_getName(unwrapped) {
let string = String(cString: ivar)
ivars.append(string)
}
}
free(ivarList)
return ivars
var count: CUnsignedInt = 0
var ivars = [String]()
let ivarList = class_copyIvarList(internalClass, &count)
for i in 0..<Int(count) {
let unwrapped = ivarList?[i].unsafelyUnwrapped
guard let ivar = ivar_getName(unwrapped) else { continue }
let string = String(cString: ivar)
ivars.append(string)
}
free(ivarList)
return ivars
}


/// Get all selectors implemented by the class.
///
/// - Returns: An array of selectors.
public var selectors: [Selector] {
get {
var count: CUnsignedInt = 0
var selectors = [Selector]()
let methodList = class_copyMethodList(internalClass, &count)
for i in (0..<Int(count)) {
let unwrapped = methodList?[i].unsafelyUnwrapped
if let selector = method_getName(unwrapped) {
selectors.append(selector)
}
}
free(methodList)
return selectors
var count: CUnsignedInt = 0
var selectors = [Selector]()
let methodList = class_copyMethodList(internalClass, &count)
for i in 0..<Int(count) {
let unwrapped = methodList?[i].unsafelyUnwrapped
guard let selector = method_getName(unwrapped) else { continue }
selectors.append(selector)
}
free(methodList)
return selectors
}

/// Get all protocols implemented by the class.
///
/// - Returns: An array of protocol names.
public var protocols: [String] {
get {
var count: CUnsignedInt = 0
var protocols = [String]()
let protocolList = class_copyProtocolList(internalClass, &count)
for i in (0..<Int(count)) {
let unwrapped = protocolList?[i].unsafelyUnwrapped
if let protocolName = protocol_getName(unwrapped) {
let string = String(cString: protocolName)
protocols.append(string)
}
}
return protocols
var count: CUnsignedInt = 0
var protocols = [String]()
let protocolList = class_copyProtocolList(internalClass, &count)
for i in 0..<Int(count) {
let unwrapped = protocolList?[i].unsafelyUnwrapped
guard let protocolName = protocol_getName(unwrapped) else { continue }
let string = String(cString: protocolName)
protocols.append(string)
}
return protocols
}

/// Get all properties implemented by the class.
///
/// - Returns: An array of property names.
public var properties: [String] {
get {
var count: CUnsignedInt = 0
var properties = [String]()
let propertyList = class_copyPropertyList(internalClass, &count)
for i in (0..<Int(count)) {
let unwrapped = propertyList?[i].unsafelyUnwrapped
if let propretyName = property_getName(unwrapped) {
let string = String(cString: propretyName)
properties.append(string)
}
}
free(propertyList)
return properties
var count: CUnsignedInt = 0
var properties = [String]()
let propertyList = class_copyPropertyList(internalClass, &count)
for i in 0..<Int(count) {
let unwrapped = propertyList?[i].unsafelyUnwrapped
guard let propretyName = property_getName(unwrapped) else { continue }
let string = String(cString: propretyName)
properties.append(string)
}
free(propertyList)
return properties
}

}
Expand Down
19 changes: 9 additions & 10 deletions ObjectiveKit/RuntimeClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ public class RuntimeClass: NSObject, ObjectiveKitRuntimeModification {

/// Register class. Required before usage. Happens automatically on allocate.
public func register() {
if registered == false {
registered = true
objc_registerClassPair(internalClass)
}
guard registered == false else { return }
registered = true
objc_registerClassPair(internalClass)
}

/// Allocate an instance of a new custom class at runtime.
Expand Down Expand Up @@ -79,12 +78,12 @@ public enum ObjectiveType: Int {

func encoding() -> String {
switch self {
case .NSString: return "@"
case .NSObject: return "@"
case .Float: return "f"
case .Int: return "i"
case .Double: return "d"
case .Void: return "v"
case .NSString: return "@"
case .NSObject: return "@"
case .Float: return "f"
case .Int: return "i"
case .Double: return "d"
case .Void: return "v"
}
}

Expand Down