Hey guys.
var d = 5
var s = "String of words"
var words = s.split(separator: " ")
var howMany = words.count
var howLong = words[2].count
var result = [words[0].count]
for b in 0..<howMany {
var tem = words[0].count
if result > tem {
result = tem
}
}
line 8 and 9 displays the following info:
Cannot convert value of type '[Int]' to expected argument type 'Int'
What am I doing wrong?
Any help appriciated.
Thank You
Post
Replies
Boosts
Views
Activity
Hi,
Id like to split the string = "aabbccddee". .split function requires you to use some sort of separator. Any suggestion how to make it?
The main task is actually to count how many times the letters appear in a string. I believe the solution may be related to .map.
Any help appreciated.
Hey guys. Here is what I am trying to do:
Ive created and UIImageView that displays an image.
Ive created an UILabel (3/4 size of the image)
When I tap an image, Id like that UILabel to cover part of that image.
Any clues how to do that? Ive tried addTapGestureRecognizer but Im not sure how to do it in a best way. Any help appreciated.
Ive seen some documentation but I don't not understand how to use those informations in practise.
Hey. I googled for the solution but haven't seen anything posted less than a year ago, so Im here. I am trying to adjust UIButtons, images, all the layout of my app to the size of smaller screen like iPhone 7 and SE 2nd generations. Rest of the layout is fine. Is there any way to change layout specifically just to those two models? If not, how can I do it instead?
Many thanks for help.
Hey guys. I am having a little one with the ARKit. Not gonna lie that things is dope. Anyway,
These are CGFloat values for SCNSphere
ballNode.position = SCNVector3(0.5, -0.3, -1)
These are for SCNText
labelNode.position = SCNVector3(-50, 0, -100)
To place the Sphere where I wanted to I had to use, I Suppose, meters.
However for placing the Text I used centimetres. Why? Would anyone be that helpful and redirected me to some documentation about this as I did not find anything? Many Thanks
Hey guys. I am trying to add UITableView do the View of my VC. On top of the VC I added to UIViews with the custom elements and they work just fine. However. When I am trying to add UITableView, it pushes UIViews from above out of the screen.
Syntax error - https://developer.apple.com/forums/content/attachment/04148dec-e53f-4473-b647-e317c8709e6e
noteTableView = UITableView(frame: .zero)
view.addSubview(noteTableView)
noteTableView.layer.borderColor = UIColor.systemRed.cgColor
noteTableView.layer.borderWidth = 5
NSLayoutConstraint.activate([
noteTableView.topAnchor.constraint(equalTo: addNoteView.bottomAnchor, constant: 0),
noteTableView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0),
noteTableView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0),
noteTableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0),
])
}
This is how I configured it. addNoteView is the UIView above. What am I doing wrong?
Many thanks for help
Hey guys. Cut to the chase. Trynna create some cells in my CollectionView. Cells will populate with the object of type Tweet.
Some Tweet(s) has urlToExpand, some has value nil. Based on that, button "See more" will be visible or nah. I am certain that the data is passed correctly into Cell as I have checked it with the print. However button works randomly. Sometimes it does display, sometimes it doesn't. I have no idea why.
Here is my dataSource update in VC
private func configureDataSource() {
				dataSource = UICollectionViewDiffableDataSource<Section, Tweet>(collectionView: collectionView, cellProvider: { (collectionView, indexPath, tweet) -> UICollectionViewCell? in
						let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SearchTweetsCell.reuseId, for: indexPath) as! SearchTweetsCell
						
						cell.set(with: tweet, user: self.user)
						cell.delegateSafari = self
						
						return cell
				})
				
				dataSource.supplementaryViewProvider = { (collectionView, kind, indexPath) in
						let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: SearchTweetsVCCollectionHeader.reuseId, for: indexPath) as! SearchTweetsVCCollectionHeader
						header.set(with: self.user)
						return header
				}
		}
Here is the function from collectionViewCell that I am calling in my cv while populating cells.
func set(with usersTweet: Tweet, user: User) {
				self.user															 = user
				tweet																	 = usersTweet
				urlString															 = usersTweet.urlToExpandWithSafari
				tweetBodyLabel.text										 = usersTweet.tweetText
				timeDateLabel.text											= usersTweet.createdAt.formatToTwitterPostDate()
				
				sharesView.set(itemInfoType: .shares,	 with: usersTweet.retweetCounter.convertToKMFormatStr())
				likesView.set(itemInfoType: .likes,		 with: usersTweet.likesCounter.convertToKMFormatStr())
				
				guard tweet.urlToExpandWithSafari != nil else {
						DispatchQueue.main.async { self.goSafariButton.removeFromSuperview() }
						goSafariButton.isEnabled = false
						return
				}
				DispatchQueue.main.async { self.goSafariButton.setTitle(TweetStrings.seeFull, for: .normal) }
		}
Many thanks for any help.
Hey guys. I've created that function to animate my button:
private func animateButtonView(_ viewToAnimate: UIView) {
UIView.animate(withDuration: 0.2, animations: {viewToAnimate.alpha = 0}) { [weak self] (true) in
guard let self = self else { return }
switch true {
case true:
DispatchQueue.main.async { self.addToFavoritesButton.setImage(SFSymbolsAsImg.checkmark, for: .normal) }
UIView.animate(withDuration: 0.2, animations: {viewToAnimate.alpha = 1} )
case false:
return
}
}
}
But the problem is that animation does not finish. Alpha stays at around probably 85% from what I can see. Any help explaining what is wrong with this code will be appreciated! Many thanks.
Hey guys. I am having an issue with one of my projects.
UICollectionViewCell in my UICollectionView has a plus button with the systemImage "plus". When clicked, its changing to systemImage "checkmark".
The issue is, clicking one button, changes UI for every fifth cell.
On top of that, animation does not finish. Alpha goes to 0, and then the image is being changed, alpha should go to 1 but never gets there. It stops somewhere between 0.7-0.8.
Here is my animation block:
private func animateButtonView(_ viewToAnimate: UIView) {
UIView.animate(withDuration: 0.2, animations: {viewToAnimate.alpha = 0}) { [weak self] (true) in
guard let self = self else { return }
switch true {
case true:
DispatchQueue.main.async {
self.addToFavoritesButton.setImage(SFSymbolsAsImg.checkmark, for: .normal)
}
UIView.animate(withDuration: 0.2, animations: {viewToAnimate.alpha = 1} )
case false:
return
}
}
}
Animation block is executed in my objective function that is called in addTarget for a button.
I've asked that question on many forums and got not much.
I'll appreciate any help. Many thanks!
Hey guys. I am trying to understand the way that Coordinator works. I am cathing myself in building my own the way I shall not (created a function that passes a ViewController which, as I understand, defeats the purpose of a Coordinator.
Let us say I have 3 Diffrent ViewControllers that may be initialised from HomeVC depending on a Button. My way of thinking tells me to create something like this:
Swift
class MainCoordinator: Coordinator {
var navigationController: UINavigationController?
func pushVCWithUser(viewController: UIViewController & Coordinating, isNavigationHidden: Bool) {
var pushedVC: UIViewController & Coordinating = viewController
pushedVC.coordinator = self
navigationController?.setNavigationBarHidden(isNavigationHidden, animated: true)
navigationController?.pushViewController(pushedVC, animated: true)
}
}
and just to initialize it in my VC. But it's not the way it supposed to be done I assume. Or is it actually?
Another way:
I have seen some tutorials when a guy used Enum for cases and created a separate function for each case. But then I don't know how would I pass some parameters while initializing another ViewController.
Or shall I rather create a function like the one above but for each individual View Controller and pass the parameter (let us say that VCs are initialized with the number: Int) in a function signature?
Many thanks for any any help!
Hey guys. I am looking for some workflow for designing elements and animation so I can translate it later into a code in SwiftUI.
Could you recommend something? I am looking for something that is a graph pad-like and allows using bezier functions etc.
Many thanks for help!
Hello everyone,
I've got my project written in Objective-C. I am learning about bridging.
I bridged successfully Swift into my Objective-C project. I did some VC pushing between Objective-C VC and Swift VC. Everything works as it supposed to.
However, I created the reference to my Objective-C NetworkManager (I used Singleton pattern) in my Swift file like that: let networkManager = NetworkManager.sharedManager()
For some reason I cannot use methods from it. networkManager.getUserInfo() // .getUserInfo() will not appear!
Just to show you how I've created my NetworkManager as a Singleton. I found that solution online and it was quite old, if you have any better solution, I would be more than happy to get some insight:
(id)sharedManager {
static NetworkManager *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
(id)init {
if (self = [super init]) {
someProperty = @"Default Property Value";
self.cache = [[NSCache alloc] init];
}
return self;
}
Not sure what is the issue here. Thank you all for the help.
Hello everyone, I am getting that error all the time:
Communication with Apple failed. Your maximum App ID limit has been reached. You may create up to 10 App IDs every 7 days.
I haven't build a single application on my phone for a quite long time. It says 10 App IDs every 7 days.
What could be wrong? thanks
I am testing iOS15 and some new functionalities of UIKit. I've encountered some issues, not sure how to solve them. I did not change that code. This is just a piece of code that worked perfectly with the iOS 14, now after updating my target, it throws an error.
Xcode crashes the moment when my custom header for the UICollectionView of type UICollectionElementKindSectionHeader is being returned for the dataSource. Here is my code:
private func configureDataSource() {
dataSource = UICollectionViewDiffableDataSource<Section, Follower>(collectionView: collectionView, cellProvider: { (collectionView, indexPath, followers) -> UICollectionViewCell? in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FollowerCell.reuseId, for: indexPath) as! FollowerCell
cell.set(on: followers)
return cell
})
dataSource.supplementaryViewProvider = { (collectionView, kind, indexPath) in
let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: FollowersCollectionHeaderView.reuseId,
for: indexPath) as! FollowersCollectionHeaderView
header.set(with: self.user)
return header
}
}
The log says:
the view returned from
-collectionView:viewForSupplementaryElementOfKind:atIndexPath: does not match the element kind it is being used for. When asked for a view
of element kind 'FollowersCollectionHeaderView' the data source
dequeued a view registered for the element kind
'UICollectionElementKindSectionHeader'.
I did cast UICollectionElementKindSectionHeader to FollowersCollectionHeaderView, therefore I am not sure what is the issue here.
I've watched WWDC21 what's new in UIKit but haven't seen any mentioning of any change for that particular code.
Any suggestions, what to fix in that code?
Hello everyone,
I am learning about ARKit, SceneKit, etc.
To deeply understand SceneKit, I wanted to go through that video. Sadly, when clicked, it takes me nowhere. I cannot find that video through the Developer app either.
Anyone happened to know what may be the reason for that?
Thanks