Questions tagged [swift]

86041 questions
1

votes
1

answer
311

Views

How to set custom font with specific size to Web View in iOS?

I am trying to set Open sans with size 15 to a UIwebview. But i am not able to implement that successfully. This is what i have been trying so far let content = '' + jsonObject.stringValue + '' self.webViewOutlet.loadHTMLString(content, baseURL: nil) Can someone help to implement this Thanks in ad...
Jobins John
1

votes
1

answer
301

Views

Can UIApplicationOpenURLOptionsKey.sourceApplication be nil?

Recently after a new app update, we start getting crash in line let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String in the following code. I am just wondering why it can be nil or is it crashing because of as! to string? func application(_ app: UIApplication...
kidsid49
1

votes
0

answer
124

Views

How to adjust constraints with collapsing SearchBar in large iOS11 NavigationBar

How do I adjust the constraint when pushing a new UIViewController when a UISearchController is implemented as self.navigationItem.searchController = search New controller pushed: SearchBar collapses but leaves View with constrait to top = 0 on the initial position. (The background of the ViewContr...
David Seek
1

votes
0

answer
832

Views

iOS-Mobile Number validation based on Country

I have been working on iOS project where the requirement is validate international mobile number based on country code. I have used the phonenumberkit iOS library but I cannot validate mobile number using following code . static func validatePhoneNumber(cellPhone:String,countryCode:String,countryNam...
Srini
1

votes
2

answer
323

Views

UITextField without get property swift 4

I have custom control which contains textField. Sample code looks like this: @IBDesignable class MyTextField: UIView { private var _text: String? private var textField: UITextField? @IBInspectable var text: String? { get { return _text } set (newValue) { guard let txt = newValue else { return } self...
emerog
1

votes
0

answer
738

Views

Swift - CABasicAnimation not working with CALayer

Here is my code about add a layer with animation added. let myLayer: CALayer = .init() let myAnimation: CABasicAnimation = .init(keyPath: 'bounds.size.height') // for myLayer to center of superview let centerPoint: CGPoint = .init(x: mySuperview.bounds.width / 2, y: mySuperview.bounds.height / 2) my...
Byoth
1

votes
1

answer
275

Views

How can I fix the following error in Xcode: Key Commands must all have a Title, Key, and Selector? [duplicate]

This question already has an answer here: Key Commands must all have a Title, Key and Selector 3 answers I have been trying to figure out why I am getting this error: Key Commands must all have a Title, Key, and Selector. Every time I open a new project, this error occurs before I change anything....
Jack Nordquist
1

votes
1

answer
433

Views

ios resize scrollview by containerview with tavleview inside

I have next structure of views: vc -view --safe area --scrollview ---view ----containerview1 ----containerview2 ----containerview3 -----tableviewcontroller(in containervew3) Tableviewcontroller has buttons which add or remove rows, I want to resize scroll view that it shows full tableview content(wi...
Anton Lisitsyn
1

votes
1

answer
179

Views

save with file manager in swift4

I am trying to save the emojis in this app that I learned in apple book but the problem is that I don't understand the next steps in the book, create a static loadSampleEmojis() method that will create and return a predefined[Emoji]collection.You can use the list assigned to emojis in EmojiTableView...
user8058965
1

votes
1

answer
86

Views

Feedback json format wrong

This is my feedback json string: {'name':'abc', 'cardNumber':'1234567890', 'data': [{A data},{B data}...]} I use this function to send data, then get json and encode: func uploadData(word:String){ var request = URLRequest(url: url!, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterv...
Howard
1

votes
0

answer
98

Views

IOBluetooth Mouse Battery Level

Is it possible to read battery levels from a Bluetooth mouse (Magic Mouse 2 in this case), using the IOBluetooth framework? Would this require writing a request as data through a L2CAP or RFCOMM channel? I got as far as reading the SDP service records, but am not sure how to proceed.
comfortablejohn
1

votes
0

answer
80

Views

Swift - Upload/Retrieve images to/from Firebase

I want my users to be able to set their profile pictures in my application. I am holding the profile datas which contains the user's profile picture as a table view cell. However, I had problems in my code. This is my table view function: func tableView(_ tableView: UITableView, cellForRowAt indexPa...
atunaysaka
1

votes
0

answer
56

Views

Array filtration of String with contains is slow

searching text from an array of Product, but data is huge, and stuck ui view and keyboard. func searchText(text: String) -> [Product]{ self.filterData = text.isEmpty ? self.productCollection : self.productCollection.filter({(product: Product) -> Bool in // If dataItem matches the searchText, ret...
Ayaz Akbar
1

votes
1

answer
308

Views

Xcode project keeps crashing after converting to Swift 4, “Class implemented in both…”

I recently converted an Xcode project to Swift 4. I fixed all the syntax errors. However, my app now crashes, after outputting an error message which starts Class MPExportableArtworkProperties is implemented in both... I have been looking around S/O but all I find is that its related to MapBox whic...
Jonathan Nairn
1

votes
1

answer
70

Views

Swift UITableViewCell reusing is messing up tags / app has wrong calculation

I am making unit converter app with custom cells, every cell has a textbox inside and the idea was when u enter the value in one unit all units get calculated automatically, the problem is only when there are more cells and when u need to scroll when cells get reused they mess up tags and because my...
Dusan Dimic
1

votes
1

answer
47

Views

How do I create a borderbody in SceneKit?

I'm trying to create a 3D Kite game in SceneKit, and I do not want my nodes to leave the screen. I know how to create a border body in SpriteKit. How do I do the same in SceneKit?
Mit Sengupta
1

votes
0

answer
87

Views

Fibonacci in linear time by using an extra pointer

I have a function to find the nth number in a fibonacci sequence, in which I am recursively calling the function. The sum is stored in a class variable and I have an extra pointer I increment every time the function gets called. This extra pointer is the gate keeper which dictates the base case of w...
paddy
1

votes
0

answer
67

Views

Keeping apps tamper proof

Currently designing an iOS app that has functionality including the transfer of in-game currency to real-world currency. ( within Xcode using swift, it’s a mobile game ) Since this app includes the prospect of real money, I couldn’t help but feel that people would tamper with the game mechanics...
callum schenk
1

votes
2

answer
73

Views

Reset or clear iOS app badge without any app interactions like open the app or push notification

Any possibility to reset/clear app badge without any app interactions such as opening the app or any push/local notifications. My need is, I want to reset my app badge starting off every day without even opening the app or with any notifications.
anasaman_p
1

votes
0

answer
139

Views

Delay in changing connection status of Multipeer connectivity once the devices are disconnected from each other

I got stuck with the MPC framework. When two devices are connected, the connection status is shown as connected. However, the console keeps giving an error of connection fails while data of two devices is in sync . The error is [ViceroyTrace] [ICE][ERROR] Send BINDING_REQUEST failed(801A0016). Al...
lulusen
1

votes
0

answer
414

Views

Random Repeating Local Notifications in Swift

TL;DR: Is it possible to have repeating, random local notifications without using APNS (or an alternative push notification service)? I am building a Core Data app that includes a bunch of objects. (We'll call them widgets.) Every day at a certain time – let's say noon – I want to send a notific...
David Vincent Gagne
1

votes
0

answer
117

Views

Loop through Dictionary in Swift

I have a dictionary which I want to append some items. **This is my dictionary which I want to achieve: ** let parameters: [String: Any] = [ { 'ResultsList': [{ 'UserId': 'b806e283-066f-4081-aafe-1fe216a57c35', 'FriendUserId': '7a2ec150-cdb3-4600-84f8-2dab970bfa0c', 'TransferDate': '2017-11-23', 'U...
Ziyaad
1

votes
1

answer
47

Views

Why UITableView calculate its contentSize based on its default rowheight(44) not custom rowHeight

here is the question: if you have 20 cells and set tableView.rowHeight = 60, and after tableView load its data , its contentSize is 44*20=880 not 20*60=1200 what should i do if i want the contentSize is 1200
LE24
1

votes
1

answer
87

Views

Change UISlider controller when Table row clicked

I want to create a UISlider that when a user selects a tableview row. It updates the min & max value moves the slider to a value set by a variable. The slider is in a different Viewcontroller then the tableview. I am passing the values to the slider using a struct (Posted below). At this point, I ca...
k.thomas
1

votes
1

answer
59

Views

find the changed properties between two objects

I'm working on a entity diff algorithm. I'm trying to find the changed properties between two objects like a before and after. Is it possible to compare two object's value? Both of them are of type Any and can't be compared. import Foundation class Person { var gender: Gender = .female let dateOfBi...
DesperateLearner
1

votes
1

answer
40

Views

Is it possible to apply type erasure to returned value in protocol?

Okay now, the title might be a little bit ambiguous, but basically, what I'm trying to achieve is the following: Let's say I have two classes that I use to fetch data from backend and they both cache the fetched data, thus, they both have an invalidateCache() method. Since they are used for data fet...
Dan Karbayev
1

votes
0

answer
42

Views

SwiftCharts- display one data point for Custom Units Scrollable graph

I would like to display one data point for Custom Units Scrollable graph (Custom Units Example). Is it possible to do it with this library? I have looked into issues and the library to check and I only see [ChartAxisValue] array to create ChartAxisModel (i.e. xModel an yModel), no function to only a...
mir
1

votes
0

answer
35

Views

TableView cellForRowAt iterates through all cells right after calling reloadData()

I used tableView alot and I know it well. but this time it works weird. I added this delegations to the class: UITableViewDelegate, UITableViewDataSource. I connected the delegates from storyBoard. cells showing currectly and everything is working fine but I wanted to add the pagination to my table...
Alfi
1

votes
0

answer
76

Views

GPU-accelerating a time-intensive function with Metal

I have a function that takes 1-3 minutes to run because it's doing some heavy lifting inside of a C++ library. The function returns a I have an ObjC wrapper around the library and a Swift extension like such: extension MyCoreLib { func runTheLongFunction() -> String { let device = MTLCreateSystemDef...
Zack Shapiro
1

votes
0

answer
83

Views

Is it possible to compile a command line app written in Swift on macOS to run on Linux?

I'm new to Swift and am writing some simple command line apps. I'm using a Mac. I know how to compile to a binary that will run on macOS but is it possible to take the same source code and compile the binary to run on Linux from a Mac? If so, any chance it could be compiled to Windows too?
Garry Pettet
1

votes
3

answer
65

Views

Why got I this error on my UISwipeGestureRecognizer?

I got this error on my UISwipeGestureRecognizer in my custom class cell manager It's working in my main UITableViewController class... I create a new instance in my ViewDidLoad with : let updateClass = updateCell() updateClass.swiper() I'm not pretty sure but on this thread, I should may be use lazy...
Danyl
1

votes
1

answer
54

Views

how can I call back to previous application problematically in ios swift?

I have made a custom keyboard in which in which i made a call of openURL(), so that I can open the containing application to capture text through OCR. Then i have made a userdefault for the application group and stored the text into it, so that the keyboard extension can read it. But the problem her...
smaaz01
1

votes
1

answer
98

Views

In-App Purchase redirects to another view controller

I am playing for couple days already with in-app purchases and found next issue (let me know if it expected behavior). I have application on TestFlight at the moment, not in Apple Store. I have a list of items that user may purchase and when user taps 'Purchase' it goes through all normal steps: pro...
Array
1

votes
0

answer
59

Views

Why would instantiating a UIWindow variable in a Swift 4.0 AppDelegate cause “uncaught exception of type NSException” to be thrown?

Here is some code that was working prior to Christmas: class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application ( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [ UIApplicationLaunchOptionsKey : Any ]? ) -> Bool { window = UIWindow( f...
Joseph Beuys' Mum
1

votes
2

answer
33

Views

Search Controller for words

I have followed below example code for search feature in my application https://www.raywenderlich.com/157864/uisearchcontroller-tutorial-getting-started Everything is working fine and searching is also working perfectly. but when I enter the words in different order/sequence it does not give me the...
Bindi Manek
1

votes
0

answer
347

Views

Swift class in ObjC Project : Receiver 'MySwiftClass' for class message is a forward declaration

After spending a few hours to integrate swift files successfully to my Objective-C based iOS project, I face the next challenge now : In one of my Objective-C class header (Say, MyObjCClass.h), I do the forward declaration for MySwiftClass. In the respective .m file, I define an instance of MySwiftC...
Harish J
1

votes
0

answer
40

Views

Presenting from UISearchController causes NSException

So I'm a bit stumped on this one. My app used to work and after going to XCode 9 this seems to have stopped working. I have a UITableViewController with an attached UISearchController to do some very simple searching. I've wired up my UITableViewController to have a resultSearchController field. Thi...
bitops
1

votes
1

answer
88

Views

How to search only for schools in Swift LocationPicker Library

I am using this library 'Location Picker' for ios swift. it basically search for places in the map, all kinds of places. Can I restrict the search for only Schools? I need to search for schools ONLY I am using swift4 and the latest xCode Thank you very much IBAction function @IBAction func pickAScho...
Hatim
1

votes
1

answer
173

Views

Converting iPhone video to mp4 and upload to PHP Server

I have an app that successfully records and uploads a file to my PHP server, unfortunately the file won't play. I received guidance that I needed to use AVAssetExportSession to convert the file to mp4 to get it to work but am having trouble incorporating this into my code correctly. I'm getting an...
techgirl
1

votes
2

answer
842

Views

Completion handler never called

I have a function like this. class func getAccountBalances(completionHandler:@escaping ((_ balances:Any) -> Void)){ //Alamofire request and we get the result. But sometimes the result fails. switch response.result { case .success(let value): completionHandler(value) case .failure(let error): print...
Nevin Jethmalani

View additional questions