nsobject

respondToSelector / performSelector with parameter from a string in Swift 3

 ̄綄美尐妖づ 提交于 2020-01-05 03:37:34
问题 I have to call method of a class. This method potentially exists or not. I'm looking for a solution from 2 hours. The following works without parameter sayHello() I have the class : class myClass: NSObject { func say(something:String){ print("I say : \(something)") } func sayHello(){ print("Hello") } } 1st step : Create a selector from a string with a parameter let selector = NSSelectorFromString("sayHello" ) let selectorWithParam = NSSelectorFromString("say:" ) 2nd step : Test if the method

Categories on NSObject — keeping it safe

无人久伴 提交于 2020-01-02 01:14:06
问题 Apple has this to say: Categories of the Root Class A category can add methods to any class, including the root class. Methods added to NSObject become available to all classes that are linked to your code. Adding methods to the root class with a category can be useful at times, but it can also be quite dangerous. Although it may seem that the modifications the category makes are well understood and of limited impact, inheritance gives them a wide scope. You may be making unintended changes

Calling super.init() in initializer of NSObject subclass in Swift

喜你入骨 提交于 2020-01-02 00:48:29
问题 I'm building an iOS app in Swift and drawing on the Lister sample project Apple provides. Lister uses two model objects: List and ListItem. I found that both of them do not call super.init() in their initializers even though they subclass NSObject. However, in the Objective-C version of Lister, both model objects (AAPLList and AAPLListItem) do call [super init] . The Swift Programming Language clearly states that “designated initializers must call a designated initializer from their immediate

Class type Objective C

感情迁移 提交于 2020-01-01 03:02:17
问题 In the NSObject protocol, it defines a method that is similar to this: -(Class) class What type of object is the Class object? Or is it even an object? What can I do with the object? Can I get the base class or adopted protocols? 回答1: Class is itself a class defined by the Objective-C runtime, akin to the Class class in Java. For example, you can use the function class_getClassName() to get the name of a class: NSObject *o = [[[NSObject alloc] init] autorelease]; NSLog(@"%s\n", class

Scalar type in Managed Object only works for IPhone 5

允我心安 提交于 2019-12-31 16:36:08
问题 Property 'Latitude' is a scalar type on class 'LatitudeLongitude'. Cannot generate a setter method for it. When I generated codes for my managed object, I got a message whether I want scalar properties for primitive data type. should I use it? I want to make this application compatible with iPhone 3 - 5 is there any issues with this problem? 回答1: When you use scalar properties you have to provide implementations of getters and setters for those properties by yourself, as described in

Is it possible to add “keyed-subscripting” to Class objects?

。_饼干妹妹 提交于 2019-12-30 10:07:12
问题 In the vein of... @implementation MyClass - (id) objectForKeyedSubscript:(id)k { return [self something:k]; } Is it also possible to "subscript" Class objects? I too, am about to find out, with you.. but thought I would post this question as I tested it out, myself... + (id) objectForKeyedSubscript:(id)k { return [self.shared something:k]; } And alas.. it is not... id x = MyClass[@"document"]; error: unexpected interface name 'MyClass': expected expression But why, Daddy? Class ' sure get the

How to pass data between viewcontrollers

让人想犯罪 __ 提交于 2019-12-25 10:01:03
问题 I have a fairly complex application at this point, and feel as though the way I am handling data is not up to scratch. So I have started taking some steps towards making my app more MVC friendly. The first of which, I have gone from having inline parser methods in all of my ViewControllers to creating a dedicated parser class. Its not hard to call I just set up the class then call the initializer method I have made which I pass the data to for my request.. everything in my object class works

iOS store Array of Objects

孤街浪徒 提交于 2019-12-25 04:46:33
问题 In my application i implemented several tableviewcontrollers that display a NSObject for each cell. Every tableviewcontroller has a different "filter" that is applied to the array so every table displays a specific group of these objects. In the viewdidload of each tableviewcontroller i load my array from NSUserdefaults, filter it, and display it. This works just fine, i am using NSCoder to get the Objects encoded/decoded for storing. For developing purposes only, i create each Object

Applying Generics to Variables and Functions - Swift

自古美人都是妖i 提交于 2019-12-25 03:14:29
问题 I'm trying to use generics in swift in order to initialise variables within my Vector3D class. However, upon assigning the protocol 'Number' to my variable (to make it either a Double or Float) I get the following error: Protocol 'Number' can only be used as a generic constraint because it has Self or associated type requirements public protocol Number { func +(l: Self, r: Self) -> Self } extension Double : Number {} extension Float : Number {} class Vector3D: NSObject { var xCord: Number var

How can I Retrieve a property value from child array object?

故事扮演 提交于 2019-12-25 00:00:46
问题 I'm trying to call an object property from a child array. In the viewcontroller the categories and subcategories are loaded with name, path and images. A new class created for sub-categories able to get name and path but can't retreive the image. The Parent categories are returning all the info including icons however the sub-categories not able to get the image. ViewController.swift segue prepare. override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if (segue.identifier! ==